escape() and unescape()
escape() and unescape() are legacy string encoding helpers from older JavaScript environments. Modern URL and text encoding should use dedicated APIs such as encodeURIComponent instead.
Overview
escape() and unescape() are legacy string encoding helpers from older JavaScript environments. Modern URL and text encoding should use dedicated APIs such as encodeURIComponent instead.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
escape Deprecated | 1 | 12 | 1 | 1 | 18 | 1 |
| Other | ||||||
javascript.builtins.unescape Deprecated The unescape() function computes a new string in which hexadecimal escape sequences are replaced with the characters that they represent. The escape sequences might be introduced by a function like escape(). | 1 | 12 | 1 | 1 | 18 | 1 |
Syntax
// escape() and unescape() example
// See MDN Web Docs for details Live demo
Encode with escape and encodeURIComponent
Compare the legacy functions with modern URL-safe encoding.
Decode encoded text
Restore the original string from an escaped sequence.
Handle non-ASCII characters
See why escape/unescape are legacy APIs for Unicode text.
Use cases
Legacy compatibility review
Identify and replace older encoding helpers when updating historical codebases.
Understanding old scripts
Recognize what escape and unescape are doing when reading older browser-oriented code.
Cautions
- These functions do not match modern URL-encoding expectations and often produce confusing behavior.
- Replace them with explicit, standards-based encoding functions whenever possible.
Accessibility
- Incorrect encoding can break user-visible text, links, or labels in ways that affect accessibility.
- Use modern encoding APIs to keep content predictable across languages and assistive tools.
Related links
Powered by web-features