Ideally, you should use encodeURI
or encodeURIComponent
to encode strings and decodeURI
or decodeURIComponent
respectively to decode a string, since escape
and unescape
are deprecated.
If you want to use escape
for encoding, use the unescape
function instead of the decodeURIComponent
function to decode the string.
From the MDN page,
The escape and unescape functions do not work properly for non-ASCII characters and are deprecated. In JavaScript 1.5 and later, use encodeURI, decodeURI, encodeURIComponent, and decodeURIComponent.
The escape and unescape functions allow you to encode and decode strings. The escape function returns the hexadecimal encoding of the argument to the ISO Latin character set. The unescape function returns an ASCII string for the specified hexadecimal value.
source share