Skip to content
Related Articles

Related Articles

JavaScript unescape() Function
  • Last Updated : 06 Jul, 2020

Prerequisite: JavaScript escape() Function

Below is the example of the unescape() function.

  • Example:




    <script>
       // Special character encoded with
       // escape function
       document.write(unescape("Geeks%20for%20Geeks%21%21%21"));
      
       document.write("<br>");
      
       // Print encoded string using escape() function
       // Also include exceptions i.e. @ and .
       document.write(unescape("To%20contribute%20articles%20contact"+
                       "%20us%20atcontribute@geeksforgeeks.org"));
    </script>                    

    
    

  • Output:
    Geeks for Geeks!!!
    To contribute articles contact us at 
    contribute@geeksforgeeks.org

The unescape() function in JavaScript takes a string as a parameter and uses to decode that string encoded by the escape() function. The hexadecimal sequence in the string is replaced by the characters they represent when decoded via unescape().

Syntax:

unescape(string)

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



  • string: This parameters holds the string that will be decoded.

    Return value: This function returns a decoded string.

    Note: This function only decodes the special characters, this function is depricated.
    Exceptions: @ – + . / * _

    More example codes for the above function are as follows:
    Program 1:




    <script>
       // Special character encoded with
       // escape function
       var str = escape("Geeks for Geeks!!!");
       document.write("Encoded : " + str);
      
       // New Line
       document.write("<br>");
      
       // unescape() function
       document.write("Decoded : " + unescape(str))
      
       // New Line
       document.write("<br><br>");
      
       // The exception
       // @ and . not encoded.
       str = escape("To contribute articles contact us"
                    "at contribute@geeksforgeeks.org")
       document.write("Encoded : " + str);
      
       // New Line
       document.write("<br>");
      
       // unescape() function
       document.write("Decoded : " + unescape(str))
      
    </script>

    
    

    Output:

    Encoded : Geeks%20for%20Geeks%21%21%21
    Decoded : Geeks for Geeks!!!
    
    Encoded : To%20contribute%20articles%20contact%20us%20at%20contribute@geeksforgeeks.org
    Decoded : To contribute articles contact us at contribute@geeksforgeeks.org
    

    Supported Browsers:

    • Google Chrome
    • Internet Explorer
    • Mozilla Firefox
    • Safari
    • Opera

    full-stack-img

    My Personal Notes arrow_drop_up
Recommended Articles
Page :