JavaScript String Escaper
Escape text for JavaScript string literals ("…", '…' or `…`) with \n, \t, \" and optional \uXXXX for non-ASCII – or unescape JS strings back to text.
36 characters · 40 bytes (UTF-8)
0 characters · 0 bytes (UTF-8)
Runs entirely in your browser. Your data is never uploaded.
What is JavaScript Escape?
Turns any text into the content of a valid JavaScript string literal for the quote style you choose, and converts escaped JS strings back to plain text.
How to use JavaScript Escape
- Choose Escape or Unescape.
- For escaping, choose the String delimiter (double, single or template literal) and optionally Escape non-ASCII as \uXXXX.
- Paste text into Input and copy the Output between your quotes.
Example
Path: C:\temp "new"
Path: C:\\temp \"new\"
Double-quote delimiter.
When to use JavaScript Escape
Use it when hard-coding text, templates or JSON-like data into JavaScript or TypeScript source. To embed data into HTML <script> tags also make sure </script> cannot appear; for JSON data use JSON.stringify or the Escape/Unescape tool’s JSON format.
How JavaScript Escape works
Escaping replaces backslash, newline, carriage return, tab, backspace, form feed and vertical tab with \\ \n \r \t \b \f \v; the chosen quote character gets a backslash (for template literals also ${); other control characters become \xHH, and U+2028/U+2029 are always escaped because they break older parsers. With the non-ASCII option every character above U+007E becomes \uXXXX (surrogate pairs for emoji). Unescaping understands all JS escapes including \u{…}, \xHH, legacy octal and line continuations.
Common Use Cases
- Pasting multi-line text into a JS string constant
- Escaping quotes in strings for code generators
- Producing ASCII-only source files with \u escapes
- Reading escaped strings from minified code or logs
FAQs
Which quote characters are escaped?
Only the one you choose as delimiter (plus backtick and ${ in template mode), so the output stays readable.
Why are U+2028 and U+2029 escaped?
They were treated as line terminators inside string literals before ES2019 and can break code in older engines.
Is the output valid JSON?
Not always – JSON does not allow \x, \v or single-quoted strings. Use the JSON format of the Escape/Unescape tool for JSON.