Free Online JavaScript Escape Tool
Escape and unescape strings for JavaScript source code.
Escaping produces a JavaScript string literal fragment: line breaks, tabs, backslashes, quotes, and control
characters become escape sequences. Unescaping reverses that process, including \xNN and
\uNNNN forms.
About the JavaScript Escape Tool
Text and source code live under different rules. A paragraph may contain a newline, a quotation mark, or an ampersand without complaint, but place the same characters inside a JavaScript string literal and the parser will object. Escaping is the translation layer between the two worlds. This tool converts ordinary text into safe escape sequences for a string literal, and it can also decode an existing literal back into readable content when you need to inspect what a script is actually producing.
What gets escaped
- Line breaks and tabs: carriage return, newline, tab, backspace, form feed, and vertical tab become short sequences such as
\nand\t. - Quotes and backslashes: both quote styles and the backslash itself are protected so the literal cannot terminate early.
- Control characters: bytes below 0x20 and the Unicode line separators U+2028 and U+2029 are encoded as
\uXXXX. - Non-ASCII: optional encoding converts accented letters, emoji, and other symbols into portable Unicode escapes.
Choosing an escape strategy depends on context. JSON embedded in HTML, a template string inside server-rendered
JavaScript, and a value passed to eval all have different risk profiles. This tool focuses on the
JavaScript string layer: it makes a value safe to place between quotes. It does not perform HTML escaping, URL
encoding, or SQL quoting, and it is not a substitute for parameterized queries or a templating engine that
escapes output automatically. Use the tool that matches the destination format.
The unescape direction is useful when reading minified code, inspecting values captured from a network response, or checking a string copied out of a database dump. The decoder understands the common single character escapes, hexadecimal byte escapes, four digit Unicode escapes, and the newer brace form. It handles line continuations, where a backslash at the end of a line joins the next line without inserting a character. If the input begins and ends with a matching quote, that wrapper can be removed automatically.
Both directions run locally with a short delay after you type. The output box reports character counts so you can see how much the escaped form grows, which is often useful when a payload has a strict size limit. Long input is fine, but extremely large strings will still consume memory because the conversion is performed on the main thread. Everything is copied or downloaded as plain text, so the result can be pasted into an editor, a configuration file, or a test fixture immediately.
How to use this tool
- Choose Escape to encode text, or Unescape to decode an existing literal.
- Paste the content into the input box.
- Select quote handling and, for escaping, whether non-ASCII characters should be written as Unicode escapes.
- Copy the result or download it as a text file.
Frequently asked questions
Does escaping make a string safe for HTML or SQL?
No. JavaScript escaping protects a string literal in JavaScript source. HTML, SQL, URLs, and regular expressions each need their own escaping rules. Use context-appropriate encoding and parameterized APIs.
Why did my emoji turn into two escape sequences?
JavaScript strings are sequences of UTF-16 code units. Characters outside the basic multilingual plane, including most emoji, are represented by a surrogate pair, so the escaped form contains two four-digit sequences. Together they decode back to the original character.
Can I paste a string that still has its quotes?
Yes. Enable the option to remove surrounding quotes when unescaping. The tool only removes one matching pair at the very start and end, leaving quotes inside the content alone.