Skip to content

Javascript Escape / Unescape

Escape or unescape JavaScript strings.

Loading…

About Javascript Escape / Unescape

Dropping user text or a long snippet into a JavaScript string goes wrong in several ways at once: a stray quote ends the literal, a backtick or ${ fires a template, and a closing script tag can end an inline script early. Escape rewrites all of those, plus control characters, so the result works in a single-quoted, double-quoted or backtick string. Unescape decodes the common sequences back to text without evaluating anything.

Features

  • Escapes backslashes, single and double quotes and backticks
  • Escapes ${ so template literals do not interpolate
  • Writes < and > as \x3C and \x3E, so a script end tag cannot close an inline script
  • Control characters become \n, \t or \xHH, and U+2028 and U+2029 become \u2028 and \u2029
  • Unescape decodes \xHH, \uHHHH, \u{code point} and \0 without running any code

Limitations

  • Non-ASCII characters such as é and emoji are left as they are, not converted to \u sequences.
  • Regular expression characters such as . and * are not escaped, so the output is for strings, not for building a pattern.

How it works

  1. Paste the text or the escaped string into the JAVASCRIPT Input panel.
  2. Select Escape or Unescape with the toggle in the middle column.
  3. Read the JAVASCRIPT Output panel, which updates as you type.
  4. Select Copy Output, then wrap the result in whichever quote style your code uses.

Example input

She said "hello"
New line with a \ backslash

Frequently asked questions