JavaScript Escape / Unescape
Escape text into a JavaScript string literal or decode escape sequences.
JavaScript Escape and Unescape Online
Turn any text into a safe JavaScript string literal, or decode an escaped JS string back into readable text. The escaper handles quotes, backslashes, control characters, and optionally all non-ASCII characters, so you can paste the result between quotes in your source code, a bookmarklet, a JSON-like config, or a browser console snippet without syntax errors.
What gets escaped
- the backslash
` →\` - the chosen quote:
"→",'→', or for template literals`→`and$→$ - line breaks and whitespace controls:
\n,\r,\t,\b,\f,\v,\0 - other control characters as
\xHH, e.g. the ANSI escape character →\x1B - U+2028 and U+2029, which broke string literals in engines before ES2019
Only the quote style you select is escaped, which keeps the output short: inside "..." an apostrophe like don't stays as is.
Options
- Quote style – double quotes, single quotes, or backtick template literals.
- Non-ASCII – keep
€and emoji as is (fine for UTF-8 source files) or escape them as\u20ACand surrogate pairs like\uD83D\uDE80for ASCII-only bundles and legacy tooling.
Unescaping strings from logs and minified code
Minified bundles, source maps, and server logs often contain strings such as "Line 1\nLine 2\u00e9". Paste them into Unescape to see the actual text. The decoder understands \u{...} code point escapes, hex, octal, and line continuations.
Pitfalls
Building HTML inside JavaScript strings needs two layers of escaping: first for HTML, then for the JS literal. Also avoid eval() on user input – escaping is for writing literals, not a sandbox. For data interchange prefer JSON Escape / Unescape; for markup see HTML Escape / Unescape.
Frequently Asked Questions
Why does 'C:\temp\new' print a tab and a line break?
In a JavaScript string the backslash starts an escape sequence, so \t becomes a tab and \n a newline. To keep literal backslashes you must double them: 'C:\\temp\\new'. Paste the path into Escape mode to get the correct literal, or use String.raw`C:\temp\new`.
What must be escaped inside a template literal?
Backticks (\`), backslashes, and the ${ sequence, which would otherwise start an interpolation. Real line breaks are allowed in template literals, but this tool still writes them as \n so the output stays on one line; choose the backtick quote style to get \` and \$ escapes.
Is the output valid JSON as well?
Not always. JavaScript escapes such as \', \v, \0, and \x1B are not allowed in JSON. If the result goes into a .json file or an API payload, use the JSON Escape tool, which only emits escapes the JSON grammar accepts.
Which escape sequences can the unescaper read?
All JavaScript forms: \n \r \t \b \f \v \0, quote escapes, \xHH, \uHHHH, code point escapes like \u{1F680}, legacy octal escapes, and line continuations (a backslash at the end of a line).