JavaScript encodeURIComponent() Function

Definition and Usage

encodeURIComponent() The function encodes URI components.

This function encodes special characters. In addition, it also encodes the following characters: , / ? : @ & = + $ #

Tip:Use decodeURIComponent() The function decodes encoded URI components.

Example

Encode URI:

var uri = "https://codew3c.com/my test.asp?name=stale&car=saab";
var res = encodeURIComponent(uri);

Try it yourself

Syntax

encodeURIComponent(uri)

Parameter value

Parameter Description
uri Must. The URI to be encoded.

Technical Details

Return Value: A string representing the encoded URI.

Browser Support

Function Chrome Edge Firefox Safari Opera
encodeURIComponent() Support Support Support Support Support