JavaScript Escape / Unescape
Escape a string into a JavaScript string-literal-safe form (backslash-escaping quotes, backslashes, newlines, tabs, and control characters) or unescape JS escape sequences (\n, \t, \xHH, \uHHHH, \u{...}) back into plain text.
Input
Output
Guides
The JavaScript Escape / Unescape tool converts text to and from the form it takes inside a JavaScript string literal. Paste raw text and get back a version that is safe to drop between quotes in your code, or paste an escaped string and get the original characters back. Everything runs in your browser, so nothing you type is uploaded.
What it does
Escape takes a plain string and backslash-escapes the characters that would otherwise break a JavaScript string literal:
- Backslash
\becomes\\ - Double quote
"becomes\"and single quote'becomes\', so the result is safe inside either quote style - Newline, carriage return and tab become
\n,\rand\t - Backspace, form feed, vertical tab and the null character become
\b,\f,\vand\0 - Any other control character (code point below 0x20, plus DEL 0x7F) becomes a
\xHHhex escape
Ordinary printable text — including accented letters, emoji and other Unicode — is left exactly as it is. The tool deliberately does not "over-escape" readable characters into \uXXXX, keeping the output compact and legible.
Unescape reverses the process. It reads the escape sequences a JavaScript string can contain and turns them back into real characters: \n, \r, \t, \b, \f, \v, \0, \\, \", \', the backtick escape \`, hex escapes \xHH, four-digit \uHHHH, and the ES6 code-point form \u{H...} (which can represent characters beyond the basic plane, such as emoji).
How to use it
- Paste your text into the input box.
- Choose Escape or Unescape from the Mode dropdown.
- The result appears instantly and can be copied or downloaded.
Switch modes to round-trip a value: escape a string, then unescape the result to confirm you get the original back.
How are unknown escape sequences handled?
Following the JavaScript specification, an unrecognized escape such as \q simply drops the backslash and keeps the letter, producing q. Malformed hex or Unicode escapes (for example a \x not followed by two hex digits) degrade the same way rather than raising an error, so the tool never fails on messy input.
Does it wrap the output in quotes?
No. The escaped output is the string contents only, without surrounding quote characters, so you can paste it inside whichever quote style your code uses. Because both ' and " are escaped, the result is valid inside single quotes, double quotes or a template literal.
Is my data private?
Yes. All escaping and unescaping happens locally in your browser using plain JavaScript. Your text is never sent to a server, which makes the tool safe for snippets, configuration values and other sensitive strings.
When is this useful?
Any time you need to embed text in code: hard-coding a multi-line message, pasting a Windows file path (full of backslashes) into a script, cleaning up a string copied out of a minified bundle, or decoding a \uXXXX-laden value from a log or JSON dump back into readable text.