This is a free online tool to escape JavaScript strings. You can copy/paste your desired string in below text field and hit Escape button. This tool will help you convert simple string containing newlines \n
, quotes (e.g. "
& '
) and some special unicode characters into a quoted string literal value for JSON or Javascript programming source.
JavaScript escaping is used to represent special meaning characters in a JavaScript code. e.g. less than symbol <
has a special meaning in JavaScript programming language. But in case your data contains a less than
symbol <
and you want to send it without confusing the browser then you need to send it as &lt; instead of <
. Simlarly there are many other special characters that can be used as part of
JavaScript programming. Below sample list can give you a idea of what this means.
Character | JavaScript Escape Value |
---|---|
quote (") | \" |
single quote (') | \' |
Nul char | \0 |
Horizontal Tab | \t |
Vertical Tab | \u000B or \v |
New line | \n |
Carriage return | \r |
Backslash | \\ |
That is easy. Just type the character or a full string in the text box above and hit Escape button. You should be able to see the escaped value.
Only few special meaning character need to be escaped. These characters have special use in JavaScript programming language.
\'
, \v
and \0
escapes are considered illegal in JSON and are not allowed strings.\v
as v
instead of a vertical tab \x0B
.Escaping a String inside javascript code can be cumbersome task if the string value is large. This kind of tool can easily apply all escaping rules to avoid unwanted errors in a JavaScript code.
JSON and JavaScript escaping is not exactly same. There are few special characters that need to be escaped differently in JSON. Though, most characters are escaped the same way you can not assume it will always be same.
The JavaScript escape()
function is not same as JavaScript string literal escaping. The JavaScript escape()
function is a deprecated (since JavaScript 1.5) function that was used for URL encoding. It is recommended to use encodeURI()
instead.