Skip to content

JavaScript Escape

Escapes or unescapes a JavaScript string, replacing characters that could prevent interpretation with their escape sequences.

Loading tool...

JavaScript string escaping explained

Why escape?

JavaScript string literals can be delimited by single quotes, double quotes or backticks. A literal occurrence of the delimiter, a backslash or a raw line break inside the value breaks the literal. This tool escapes both quote characters.

Rules applied

Character Escaped as
Tab \t
Newline \n
Carriage return \r
Backspace \b
Form feed \f
Single quote \'
Double quote \"
Backslash \\
Line/paragraph separator \u2028, \u2029
Other control chars \x00 ... \x1F

Escaping is not sanitizing

Escaping quotes makes a value safe inside a string literal; it does not make it safe to inject into HTML. Use JSON.stringify() for that.

---