JavaScript escape()Function
JavaScript Global Functions
Definition and Usage
The escape() function encodes a string so that it can be read on all computers.
This method does not encode ASCII letters and digits, nor does it encode the following ASCII punctuation marks: * @ - _ + . / . All other characters are replaced by escape sequences.
Tip:Useunescape()method to decode the string.
Note:The escape() function has been removed from the Web standards, so try not to use this function; you can useencodeURIorencodeURIComponentinstead.
Syntax
escape(string)
| Parameter | Description |
|---|---|
| string | Required. The string to be escaped or encoded. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the escape() function
Tips and Notes
Note:The escape() function cannot be used to encode URIs (Uniform Resource Identifier, "URI" for short). You can use the functionencodeURI()instead.
Examples
Examples
Use escape() to encode a string:
<script>
document.write(escape("Need tips? Visit EXAMPLE!"));
</script>
document.write(escape("Need tips? Visit EXAMPLE!"));
</script>
The output of the above example is:
Need%20tips%3F%20Visit%20EXAMPLE%21
Try it yourself »
JavaScript Global Functions
Other Extensions