Back to Tools

JS Escape / Unescape

Safely escape or unescape special characters for JavaScript strings

JS PRO
Input String / Code
Transformed Output

                

Make any text safe to drop inside a JavaScript string

A stray double quote, a line break or a backslash inside a string literal is enough to break a script. This tool converts raw text into an escaped form you can paste between quotes, and it can reverse the process when you have an escaped string and want to read what it actually says. It runs in your browser: you paste text, press a button, and the result appears below the form.

How to escape or unescape a string

  1. Paste your text into the Input String / Code box, or press Sample to load an example containing a quote and a backslash.
  2. Choose Escape (To JS Safe) or Unescape (To Plain) in the Action menu.
  3. Pick an Encoding Type: Standard, Hexadecimal or Unicode.
  4. Click Transform String. The Transformed Output panel opens with a Copy button.

Editing the input hides the previous result, so you never copy stale output by accident. Paste reads from your clipboard and Clear empties the field.

What the three encoding types do

  • Standard uses the same escaping rules as JSON string encoding: quotes become \", backslashes are doubled, and newlines and tabs turn into \n and \t.
  • Hexadecimal leaves plain ASCII characters alone and rewrites anything above code 127 as \xHH. This is only meaningful for characters up to code 255, so emoji and most non-Latin text are better handled by the Unicode option.
  • Unicode rewrites every character, including letters and digits, as a \uHHHH sequence. Characters outside the basic plane come out as two surrogate escapes, which is how JavaScript represents them.

Where this helps

  • Embedding a multi-line error message or HTML snippet in a JavaScript variable without hand-escaping each line.
  • Reading a log entry or API response where text arrives as escaped sequences and you want the human version.
  • Storing text with accented or non-Latin characters in a source file that must stay pure ASCII.
  • Preparing a string for a JSON config, since Standard mode follows JSON conventions.

Limits worth knowing

Unescape works by wrapping your text in quotes and parsing it as a JSON string, so it understands \n, \t, \\, \" and \uHHHH. Hex sequences such as \x41 and single-quote escapes like \' are not valid JSON and will produce the message Invalid escape sequence. If you see that message, check for those forms or for a lone backslash at the end of the text. Also note that Hexadecimal mode is not reversible with the Unescape action for the same reason, so use Standard or Unicode when you plan to round-trip.

Related Tools


Frequently Asked Questions

What is the difference between Standard, Hexadecimal and Unicode escaping?
Standard escapes only what must be escaped, such as quotes, backslashes, newlines and tabs. Hexadecimal rewrites non-ASCII characters as \xHH, and Unicode rewrites every character as \uHHHH. Standard keeps text most readable, while Unicode gives pure-ASCII output.
Why does Unescape say Invalid escape sequence?
Unescape parses your text as a JSON string. Sequences that JSON does not allow, like \x41, \' or a trailing single backslash, make parsing fail. Convert those to \uHHHH form or remove them, then run the transformation again.
Can I round-trip Hexadecimal output back to plain text?
Not with this tool's Unescape action, because it does not understand \xHH sequences. Standard and Unicode output can be reversed, so choose one of those if you need to escape and later restore the original string.
Does the output include surrounding quotes?
No. The escaped text is returned without opening and closing quotes, so you can place it inside single or double quotes yourself. If you use single quotes, remember to escape any apostrophes in the result manually.
Does the tool send my text to a server?
The transformation is done by JavaScript running on the page, so the text you paste is processed in your browser rather than submitted to a server route. The result appears straight away under the form.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.