Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript escape() Function

Improve Article
Save Article
  • Last Updated : 13 Jan, 2023
Improve Article
Save Article

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:

  • string: This parameter holds the string that will be encoded.

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




<script>
    // Special character encoded with
    // escape function
    console.log(escape("Geeks for Geeks!!!"));
     
    // Print encoded string using escape() function
    // Also include exceptions i.e. @ and .
    console.log(escape("To contribute articles contact"+
                        " us at review-team@geeksforgeeks.org"));
</script>

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




<script>
    // Special character encoded with
    // escape function
    console.log(escape("Geeks for Geeks!!!"));
     
    // Print encoded string using escape() function
    // Also include exceptions i.e. @ and .
    console.log(escape("A Computer Science Portal"));
</script>

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




<script>
    // Special character encoded with
    // escape function
    console.log(escape("GeeksforGeeks"));
     
    // Print encoded string using escape() function
    // Also include exceptions i.e. @ and .
    console.log(escape("A#Computer-Science"+
                        "%Portal@for*Geeks"));
</script>

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:

  • Google Chrome 1 and above
  • Internet Explorer 3 and above
  • Edge 12 and above
  • Mozilla Firefox 1 and above
  • Safari 1 and above
  • Opera 3 and above

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!