JavaScript escape and unescape
Spell text so it fits inside a JavaScript string or template literal, or read escape sequences back — checked against what the language itself accepts.
- SECURE
- NO UPLOADS
- NO SIGNUP
- BROWSER BASED
- FREE
- FOREVER.
Support us with a link or a share
- Characters in
- —
- Sequences written
- —
- Characters out
- —
Nothing at the counter yet.
A textarea rewrites CRLF to LF. Browsers do it to every form field before a script can read it, so pasted text arrives with 0 CRLF pairs and 0 lone LF whatever you copied. If your line endings matter, open the file instead.
Both quote marks are always escaped, so a quoted result works between "…" and '…'. A template literal also needs every ` and $ escaped.
JavaScript accepts café and 😀 as they are. Turn this on when the file is served without a UTF-8 charset or passes through a tool that mangles it.
What gets escaped, and why
| Character | Written as | Why |
|---|---|---|
| \ | \\ | A backslash starts every other escape, so a literal one is doubled first. |
| " | \" | Ends a double-quoted string. |
| ' | \' | Ends a single-quoted string. Escaped too, so the result fits either kind of quote. |
| LF | \n | Line feed. A raw one inside quotes is a SyntaxError. |
| CR | \r | Carriage return. A SyntaxError raw inside quotes, and silently read as LF inside a template literal. |
| Tab | \t | Tab. Legal raw, but invisible and easy to lose in an editor. |
| Backspace, form feed, vertical tab | \b \f \v | U+0008, U+000C and U+000B. |
| U+2028 | \u2028 | Line separator. Legal raw since ES2019, but it ended the string in older engines and in JSONP. |
| U+2029 | \u2029 | Paragraph separator. Same history as the line separator. |
| ` | \` | Template literal only. A raw backtick ends the template. |
| $ | \$ | Template literal only. ${ starts a substitution that runs code; \$ is read as a plain dollar sign. |
| < | \x3C | Inline <script> only. The HTML parser ends the script at </script> even inside a string, before JavaScript sees it. |
| NUL | \x00 | Never \0: followed by a digit, \0 becomes a legacy octal escape, which strict mode rejects as a SyntaxError. |
| other controls, lone surrogates | \xHH · \uHHHH | Always. A lone surrogate is a valid JavaScript string value but cannot be saved as UTF-8, so only its escaped form survives a copy or a download. |
| anything else | \xHH · \uHHHH | Only when you ask for ASCII-only output. Emoji become a surrogate pair such as \uD83D\uDE00, which every engine and JSON.parse read. |
Unescaping reads every escape JavaScript defines — the single-letter ones, \xHH, \uHHHH, \u{…}, \0 and a backslash before a line break, which disappears. It never runs your text as code. Sequences strict mode rejects, such as \u12 or the octal \101, are kept as written and listed with their position.
Nothing you type or open here is uploaded, put in the URL, or written to a log. The escaping runs in this tab.
What a JavaScript escape changes in your text
A string literal in JavaScript ends at the next unescaped quote of the kind that opened
it, and it may not contain a raw line break. Text copied from a log, a form or a Windows
path rarely respects either rule. Escaping rewrites the troublesome characters as
backslash sequences the parser turns back into the originals: \" and
\' for quotes, \\ for a backslash, \n and
\r for line breaks, \t for a tab. The result can be pasted
between quotes in source code, a configuration script or a browser console and produces
exactly the string you started with.
Both quote marks are escaped every time. That makes one output valid in either quoting
style, at the cost of an extra backslash in words like it\'s. Letters with
accents and emoji stay readable unless you ask for pure ASCII.
Quoted strings, template literals and inline scripts
Backticks bring two hazards of their own. A raw backtick closes the template early, and a
dollar sign followed by an opening brace starts an embedded expression that executes. The
Template literal choice writes \` and \$ so neither can
happen, and because JavaScript ignores a needless backslash in front of those characters,
the same output still reads correctly between ordinary quotes.
A script embedded directly in HTML has a problem that no JavaScript rule explains. The
page’s HTML parser decides where the script element stops before the JavaScript engine
reads a single token, and it stops at </script even in the middle of a
string. The inline script option writes each less-than sign as \x3C, which
the HTML parser passes over and JavaScript decodes back to <.
The octal trap behind NUL, and other measured details
Many escapers write the null character as \0. That works until a digit
follows it: "\01" is a legacy octal escape, which an old sloppy-mode script
reads as U+0001 and strict mode, modules and template literals refuse to parse. This page
always writes \x00, which means NUL regardless of what comes next.
The line separator U+2028 and paragraph separator U+2029 have been legal inside string
literals since ES2019, yet before that they counted as line terminators and broke JSONP
responses and older engines, so they are escaped too. A lone surrogate, half of an emoji
without its partner, is a perfectly valid JavaScript string value, but UTF-8 has no way
to store it; copying or saving it silently produces U+FFFD. Written as
\uD800, it survives. Every one of these behaviors was checked against the
JavaScript parsers in Chromium and WebKit, not taken from memory.
Unescaping without running anything
The reverse direction decodes every escape the language defines: the single-letter
forms, two-digit \x41, four-digit \u00E9, the braced
\u{1F600}, surrogate pairs and a backslash placed before a line break, which
JavaScript treats as a line continuation and removes. It uses its own reader and never
evaluates your input, so untrusted text is safe to paste. When a sequence would throw a
SyntaxError, such as \x4g, \u12 or the octal
\101 in strict mode, it stays exactly as written and the page lists its
position. An unnecessary escape like \q is decoded to q, since
that is what the engine does, with a note so the vanished backslash is not a surprise.
Why pasted Windows line endings disappear
Browsers normalize the contents of every textarea, replacing each CR LF pair with a bare
LF before scripts on the page can see it. Text you paste here has therefore lost its
carriage returns already, and the counter beside the field shows the line endings that
actually arrived. Opening the file instead reads its bytes directly, keeps the carriage
returns, and escapes each one as \r. That matters for template literals in
particular, where a raw carriage return is quietly read as a line feed.
Neighboring string and code tools
The same text often needs a different container. For a JSON payload, JSON escaping follows stricter rules with no single quotes or hex escapes. Markup takes ampersand entities instead of backslashes: use HTML escaping for a web page and XML escaping for a feed or configuration document. To tidy a whole script, the JavaScript formatter lays it out and the JavaScript minifier shrinks it, while JavaScript to JSON turns an object literal into strict JSON.
Your text stays in this tab
Everything on this page runs as JavaScript inside your browser, and inputs large enough to slow the page move to a background worker served from the same site. There is no upload, no copy of your text in the address bar and no server log to hold it. API keys, tokens and snippets of production code are exactly what people escape, so check the network panel of your developer tools while typing if you want proof.
Questions
Which characters have to be escaped in a JavaScript string?
The backslash, the quote character that delimits the string, and line breaks. A raw line feed or carriage return between quotes is a SyntaxError, so they must be written as \n and \r. This tool also escapes both quote marks, so one result works between double or single quotes, plus the less visible control characters, the two Unicode separators U+2028 and U+2029, and unpaired surrogates. Letters outside ASCII and emoji are legal as they are.
Why is NUL written as \x00 instead of \0?
Because \0 is only a NUL when no digit follows it. "\01" is a legacy octal escape: sloppy-mode scripts read it as U+0001, and strict mode, modules and template literals reject it with a SyntaxError. An escaper that writes \0 turns text such as a NUL followed by 1 into broken or different code. \x00 means NUL whatever comes next, in every mode, so that is the only spelling this page writes. When you unescape, \0 on its own is still read as NUL.
What changes for a template literal?
Two more characters matter between backticks. A raw backtick ends the template, and a dollar sign followed by a brace starts a substitution that evaluates code. Choose Template literal and every backtick is written as \` and every dollar sign as \$, which reads back as a plain character. The same output also works inside ordinary quotes, since JavaScript reads an unnecessary backslash before those characters as nothing. Carriage returns are escaped in both modes, because a raw CR inside a template is read as a line feed.
How do I put a string inside an inline script tag safely?
Turn on the inline script option. The browser’s HTML parser finds the end of a script element before JavaScript runs, and it stops at the text </script> even when that text sits inside a string. The option writes every less-than sign as \x3C, which the HTML parser does not recognize and JavaScript reads back as <. It also covers <!-- and <script, which change how the HTML parser scans the rest of the element.
Is my text uploaded anywhere?
No. Escaping and unescaping happen in this browser tab. No request carries your text, nothing is written to a server log, and the input never appears in the address bar. Very large inputs are handed to a background worker loaded from this same site so the page stays responsive. The unescape direction decodes sequences with its own reader and never evaluates your text as code, so pasting untrusted input is safe.