JavaScript escape() Function (original) (raw)

Last Updated : 13 Jan, 2023

The Javascript escape() function takes a string as a parameter and encodes it so that it can be transmitted to any computer in any network which supports ASCII characters.

Note:

escape(): This function was used to encode special characters in a string, but it has been replaced by the encodeURI() and encodeURIComponent() functions, which provide more options and better support for different character encodings.

Syntax:

escape(string)

Parameters: This function accepts a single parameter as mentioned above and described below:

Return value: This function returns an encoded string.

Note: This function only encodes the special characters, this function is deprecated.

Exceptions: @ - + . / * _

Below is an example of the escape() function.

Example: In this example, we will simply encode a string with some signs using the JavaScript escape() Function.

javascript `

`

Output:

Geeks%20for%20Geeks%21%21%21 To%20contribute%20articles%20contact%20us%20atcontribute @geeksforgeeks.org

More example codes for the above function are as follows:

Example 1: In this example, we will simply encode a string with some signs using the JavaScript escape() Function.

javascript `

`

Output:

Geeks%20for%20Geeks%21%21%21 A%20Computer%20Science%20Portal

Example 2: In this example, we will simply encode a string with some signs using the JavaScript escape() Function.

javascript `

`

Output:

GeeksforGeeks A%23Computer-Science%25Portal@for*Geeks

We have a complete list of Javascript Functions, to check those please go through Javascript Function Complete Reference article

Supported Browsers: