unescape() is the old partner of escape(). It turns codes like %20 and %u20AC back into the characters they stand for.
It is deprecated. It still works in every browser, but it does not understand UTF-8, and it never throws an error for broken codes. Learn it so you can read old code, and use decodeURIComponent() in your own.
Remember
unescape(string);
string -> text with %XX and %uXXXX codes
returns -> a new string with the codes turned back into characters
%XX -> the character with that code (up to 255)
%uXXXX -> the character with that four-digit code
Broken codes are left as they are (no error).
DEPRECATED: use decodeURIComponent() instead.
Syntax
Call unescape() by name and give it text with codes. It returns the decoded text and does not change the original.
JavaScript
unescape(string);
Call
What it does
unescape("Hello%20World")
The code %20 becomes a space. Result: "Hello World".
unescape("%41%42%43")
Each code becomes a letter. Result: "ABC".
unescape("%u20AC")
A four-digit code becomes the euro sign.
unescape("100%")
A broken code is left alone. Result: "100%".
Part of the old JavaScript standard (ES1) and kept in browsers for backward compatibility. It is deprecated: do not use it in new code. See also: escape(), decodeURIComponent() and decodeURI().
Library declarations
JavaScript
// Global function (ES1, now in Annex B "legacy" features)
unescape(string)
// returns a string
// DEPRECATED - use decodeURIComponent() instead
Parameters
Parameter
Description
string
The text to decode. A value that is not text is converted to text first.
Return Value
Return Value
Description
A string
A copy of the text where each %XX and %uXXXX code is replaced by the character with that code. A % that is not part of a valid code is left as it is, and no error is thrown.
%E9: true
%u20AC: true
Code of the result: 8364
unescape length: 5
decodeURIComponent length: 4
How It Works
One-byte codes.%E9 is the character with code 233, the letter e with an accent.
Four-digit codes.%u20AC is the euro sign. Its code is 20AC in hexadecimal, which is 8364 in normal numbers.
The UTF-8 problem."caf%C3%A9" is how the web writes "caf\u00e9". unescape() reads %C3 and %A9 as two separate characters, so the text has 5 characters. decodeURIComponent() joins them into one letter and gives the correct length, 4.
Example 3 — See How Broken Codes Are Handled
Where decodeURIComponent() throws an error, unescape() keeps going and leaves the broken part as it is.
Broken codes stay.%zz (not hexadecimal), %4 (one digit instead of two) and %u12 (two digits instead of four) are not valid codes, so unescape() returns them unchanged.
No error. That can hide a bug. You never learn that your text was damaged.
The modern function is stricter.decodeURIComponent("100%") throws a URIError, which you can catch and handle.
Compatibility
Browser & Runtime Support
unescape() is part of the "legacy" features of JavaScript. Every browser and every Node.js version still has it, but it may be removed one day and no new code should use it.
✓ Deprecated · Still works
unescape()
Available in all browsers and in Node.js, Deno and Bun, but deprecated.
LegacyStatus
Google ChromeAll versions · Desktop & Mobile
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
OperaAll versions
Full support
Samsung InternetAll versions · Android
Full support
Android WebViewAll versions
Full support
Node.jsAll versions · Server runtime
Supported
DenoAll versions · JavaScript runtime
Supported
BunAll versions · JavaScript runtime
Supported
Internet ExplorerAll versions
Full support
unescape()Works, but avoid
Bottom line: It still runs everywhere, so old code keeps working. For new code use decodeURIComponent().
Frequently Asked Questions
It turns %XX and %uXXXX codes in text back into characters. For example unescape("Hello%20World") returns "Hello World" and unescape("%u20AC") returns the euro sign. Codes that are not valid are left as they are.
Yes. It still works in every browser and Node.js, but it is listed as a legacy feature and should not be used in new code. It does not understand UTF-8, which is what the web uses.
Use decodeURIComponent() to decode a value from a URL, or decodeURI() for a whole URL. Both understand UTF-8 and throw a URIError for broken input.
unescape() reads each %XX as a separate character, so %C3 and %A9 become two characters instead of one. decodeURIComponent("%C3%A9") understands that the two bytes belong together and returns one letter.
Yes. unescape(escape(text)) returns the original text. But the result of escape() is not a proper URL encoding, so do not send it to a server. Use encodeURIComponent() and decodeURIComponent() as a pair instead.