JS escape


escape() function converts certain non ASCII characters in a string to hexadecimal codes. It is deprecated, please use encodeURI, encodeURIComponent which have similiar functions.


escape() converts space, quotes, etc.

var str="st. John's";
var str2=escape(str);
alert(str2); //st.%20John%27s


Not all special characters will be converted, @, *, +, -, /, ., @, _, will not be converted.

var str="test@gmail.com";
var str2=escape(str);
alert(str2); //test@gmail.com


unescape() function will convert back.

var str="st. John's";
var str2=escape(str);
alert(str2); //st.%20John%27s
var str3 = unescape(str2);
alert(str3); //st. John's