Syntax error Unescape HTML entities in JavaScript?

Unescape HTML entities in JavaScript?



To unescape HTML entities in JavaScript, use the unescape() function. Let's say you want to encode special character with the unescape() function ?

document.write(unescape("Demo%20Text%20")); 

In this article, we will see two examples ?

  • Unescape Entities
  • Decode the Encoded String

Unescape Entities

Example

Lo unescape, we will use the unescape() method in JavaScript. Let us see an example ?

<!DOCTYPE html> <html> <body> <h2>Demo Heading</h2> <script> document.write(unescape("Demo%20Text%20")); </script> </body> </html>

Output

Decode the Encoded String

Use escape() for encoding and unescape() for decoding. Here, we will set a sample string under the escape() method to encode ?

var myStr = escape("Demo Text!!!");
document.write("Encoded String = " + myStr); 

After that, we will use the unescape() to decode the encoded string ?

document.write("Decoded = " + unescape(myStr)) 

Example

Let us now see the example ?

<!DOCTYPE html> <html> <body> <h2>Demo Heading</h2> <script> var myStr = escape("Demo Text!!!"); document.write("Encoded String = " + myStr); document.write("<br>"); document.write("<hr>"); document.write("Decoded = " + unescape(myStr)) </script> </body> </html>

Output

Updated on: 2023-11-12T10:48:58+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements