escape and unescape
Deprecated since 1999 and still present in every engine. Documented here so you recognise it in old code and understand why the data it produced is often subtly corrupt.
Demo
The pair is [escape, encodeURIComponent]. For plain ASCII they agree, which is why escape survived so long without obvious breakage. The second case is the silent corruption: escape emits %E9, the single Latin-1 byte for é, while encodeURIComponent emits %C3%A9, the correct UTF-8 pair — so anything decoding escape output as UTF-8 gets a replacement character. The third case is worse: 中 becomes %u4E2D, a form invented by Netscape that no URL parser, server or standard understands.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| string | string | yes | The text to encode. Code points up to 255 become %XX using the LATIN-1 byte; anything higher becomes %uXXXX, a form no standard recognises. |
Return value
string — escape percent-encodes using Latin-1 byte values, and emits the non-standard %uXXXX form for code points above 255. unescape reverses it.
Common patterns
const encoded = encodeURIComponent(value);
const text = unescape(legacyValue);
const fixed = encodeURIComponent(unescape(stored));
Examples
Pitfalls
decodeURIComponent(escape('中'))
decodeURIComponent(encodeURIComponent('中'))
escape('é')
encodeURIComponent('é')
escape('a+b/c')
encodeURIComponent('a+b/c')
escape('a')
encodeURIComponent('a')
When to use
- Never in new code
- Decoding data that was originally encoded with escape — unescape is the only thing that reads %uXXXX
- Recognising it while reading something old
- Encoding anything → encodeURIComponent
- Decoding modern percent encoding → decodeURIComponent
- Non-ASCII text → escape corrupts it, silently or otherwise
- Portable code → Annex B is optional outside browsers
Notes
FAQ
Because removing it would break old pages, and the web platform does not break old pages. Annex B is the section of the specification that documents exactly these features — deprecated, normatively optional, and permanently present.