JavaScript unescape() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Deprecated function

Definition

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);
CallWhat 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

ParameterDescription
stringThe text to decode. A value that is not text is converted to text first.

Return Value

Return ValueDescription
A stringA 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.

JavaScript Examples

Example 1 — Unescape Percent Codes

Turn codes back into spaces, symbols and letters.

JavaScript
console.log(unescape("Hello%20World"));
console.log(unescape("a%26b%3Dc"));
console.log(unescape("100%25"));
console.log(unescape("%41%42%43"));
console.log(unescape(escape("Mia & Leo!")));
Try It Yourself

How It Works

  1. Codes become characters. %20 is a space, %26 is &, %3D is = and %25 is %.
  2. Letters by code. %41, %42 and %43 are the codes of A, B and C.
  3. Round trip. unescape(escape(text)) gives back the original text. The two functions are a matching pair.

Example 2 — Read %u Codes and See the UTF-8 Problem

unescape() understands the special %uXXXX codes, but it cannot read UTF-8.

JavaScript
console.log("%E9: " + (unescape("caf%E9") === "caf\u00e9"));
console.log("%u20AC: " + (unescape("%u20AC") === "\u20ac"));
console.log("Code of the result: " + unescape("%u20AC").charCodeAt(0));

console.log("unescape length: " + unescape("caf%C3%A9").length);
console.log("decodeURIComponent length: " + decodeURIComponent("caf%C3%A9").length);
Try It Yourself

How It Works

  1. One-byte codes. %E9 is the character with code 233, the letter e with an accent.
  2. Four-digit codes. %u20AC is the euro sign. Its code is 20AC in hexadecimal, which is 8364 in normal numbers.
  3. 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.

JavaScript
console.log("100%: " + unescape("100%"));
console.log("%zz: " + unescape("%zz"));
console.log("%4: " + unescape("%4"));
console.log("%u12: " + unescape("%u12"));

try {
  decodeURIComponent("100%");
} catch (err) {
  console.log("decodeURIComponent: " + err.name);
}
Try It Yourself

How It Works

  1. 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.
  2. No error. That can hide a bug. You never learn that your text was damaged.
  3. The modern function is stricter. decodeURIComponent("100%") throws a URIError, which you can catch and handle.

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.

Legacy Status
Google Chrome All versions · Desktop & Mobile
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Opera All versions
Full support
Samsung Internet All versions · Android
Full support
Android WebView All versions
Full support
Node.js All versions · Server runtime
Supported
Deno All versions · JavaScript runtime
Supported
Bun All versions · JavaScript runtime
Supported
Internet Explorer All 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.

Back to the index

You have reached the last global function. Go back to the index to review the others or pick one to revisit.

Global Functions index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful