var str="this is some text &')";
document.write(str);
document.write("<br>");
document.write(escape(str));
The output of the above code will be
this is some text &')
this%20is%20some%20text%20%26%27%29
Deprecated : Avoid using it. Use encodeURIComponent() instead.
We can use escape function in JavaScript to make a string portable to transmit it over a network.
All the non ASCII characters are to be converted before sending them by using escape function.
The escape function will replace these non ASCII characters to its two or four digit hex format.
The escape function converts a blank space into %20, same way it converts & to %26
After conversion we can get back the original string by using another JavaScript function unscape
Now data can be transmitted over net. Now let us try to get back the original string by using unescape function. We will add one more line to the above code.
var str="this is some text &')";
document.write(str);
document.write("<br>");
document.write(escape(str));
document.write("<br>");
document.write(unescape(str));
The output of this is here ( only the last line ).
I have "&" in my query string(ex: str="avm=1&av=m&noj&ss=1"). With unescape I am doing split(unescape(str).split('&')), then I am not able to get back same key value pair. How can I get my string "m&noj" back in this scenario.
✖
We use cookies to improve your browsing experience. . Learn more