JavaScript Escape / Unescape

Escape text into a JavaScript string literal or decode escape sequences.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

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 \u20AC and surrogate pairs like \uD83D\uDE80 for 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

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`.

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.

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.

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).