escape() and unescape()
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Note: escape() is a non-standard function implemented by browsers and was only standardized for cross-engine compatibility. It is not required to be implemented by all JavaScript engines and may not work everywhere. Use encodeURIComponent() or encodeURI() if possible.
The escape() function computes a new string in which certain characters have been replaced by hexadecimal escape sequences.
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.