escape() is an old function that replaces special characters in text with codes. A space becomes %20, and a letter outside the basic range becomes a code like %u20AC.
It is deprecated. It still works in every browser, but it handles non-English letters in a way that no longer matches how the web works. Learn it so you can read old code, and use encodeURIComponent() in your own.
Remember
escape(string);
string -> the text to encode
returns -> a new string with unsafe characters as %XX or %uXXXX
NOT encoded: A-Z a-z 0-9 @ * _ + - . /
%XX -> characters up to code 255 (one byte)
%uXXXX -> every other character
DEPRECATED: use encodeURIComponent() instead.
Syntax
Call escape() by name and give it text. It returns the encoded text and does not change the original.
JavaScript
escape(string);
Call
What it does
escape("Hello World")
The space becomes %20. Result: "Hello%20World".
escape("a&b=c")
Result: "a%26b%3Dc".
escape("caf\u00e9")
The accented letter becomes a one-byte code. Result: "caf%E9".
escape("\u20ac")
The euro sign needs a four-digit code. Result: "%u20AC".
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: unescape(), encodeURIComponent() and encodeURI().
Library declarations
JavaScript
// Global function (ES1, now in Annex B "legacy" features)
escape(string)
// returns a string
// DEPRECATED - use encodeURIComponent() instead
Parameters
Parameter
Description
string
The text to encode. A value that is not text is converted to text first.
Return Value
Return Value
Description
A string
A copy of the text where every character except A-Z a-z 0-9 @ * _ + - . / is replaced by %XX (for characters with a code up to 255) or %uXXXX (for all others).
JavaScript Examples
Example 1 — Escape Special Characters
See which characters escape() changes and which it leaves alone.
escape: caf%E9%20%u20AC
encodeURIComponent: caf%C3%A9%20%E2%82%AC
Modern decode of escape(): URIError
Modern round trip: true
How It Works
Different codes.encodeURIComponent() writes UTF-8 bytes: %C3%A9 for the accented letter and %E2%82%AC for the euro sign. escape() writes %E9 and %u20AC.
Not understood elsewhere. Servers and decodeURIComponent() expect UTF-8. %E9 is not valid UTF-8, so decoding throws a URIError.
The modern pair works.encodeURIComponent() and decodeURIComponent() give the original text back. Use them in new code.
Compatibility
Browser & Runtime Support
escape() 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
escape()
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
escape()Works, but avoid
Bottom line: It still runs everywhere, so old code keeps working. For new code use encodeURIComponent().
Frequently Asked Questions
It replaces special characters in text with percent codes. Characters up to code 255 become %XX (a space is %20), and all other characters become %uXXXX (the euro sign is %u20AC). Letters, digits and @ * _ + - . / are not changed.
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 encode text as UTF-8, so other software cannot read its result.
Use encodeURIComponent() to encode a value for a URL, and encodeURI() for a whole URL. To turn the text back, use decodeURIComponent() or decodeURI().
encodeURIComponent() writes non-English characters as UTF-8 bytes (%C3%A9) and also encodes + and /. escape() writes codes such as %E9 or %u20AC and leaves + and / alone. Only the encodeURIComponent() result works as a URL value.
No. Escape sequences such as \n (new line) or \" (a quote) are written inside string literals while you write code. The escape() function encodes text at run time into %XX codes. They only share a name.