Additional JavaScript Global Functions

This topic describes some additional JavaScript global functions you can use.

escape() and unescape()

The JavaScript escape() and unescape() functions can be used to encode strings that contain characters with special meanings or outside the ASCII character set.

The escape() function encodes a string. This function makes a string portable, so it can be transmitted across any network to any computer that supports ASCII characters.

The function does not encode A-Z, a-z, and 0-9. Additionally, the function encodes all other characters with the exception of: "*", "@", "-", "_", "+", ".", "/".

The escape() function maps:

!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~

To:

%20%21%22%23%24%25%26%27%28%29*+%2C-./0123456789%3A%3B%3C%3D%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E

encodeURI() and decodeURI()

The encodeURI() function is similar to the escape() function but encodes fewer character. Encoding the string:

!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~

Will produce:

%20!%22#$%25&'()*+,-./0123456789:;%3c=%3e?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5b%5c%5d%5e_%60abcdefghijklmnopqrstuvwxyz%7b%7c%7d~

So only the following characters are encoded:

SPACE, "“", "&", "<", ">", "[", "\", "]", "^", "`", "{", "|", "}"

encodeURIComponent() and decodeURIComponent()

These functions are similar to the encodeURI() and decodeURI() methods, but they additionally encode and decode the following characters:

, / ? : @ & = + $ #