100% local — your data never leaves your browser

JavaScript Escape — Paste It Into a Literal

Escape text for a JavaScript string literal: backslashes, all three quote styles and control characters, so the line compiles wherever you drop it.

Instant Private Zero cookies

Text input

JS Escaped output

What this tool does

It turns arbitrary text into something you can paste between quotes in JavaScript or TypeScript without breaking the literal:

  • backslashes are doubled, so C:\path stays a path and does not become an escape sequence;
  • ', " and ` are all escaped, so the result is valid in any of the three quote styles;
  • newline, carriage return, tab, backspace, form feed and vertical tab get their named forms — \n, \r, \t, \b, \f, \v;
  • any other character below U+0020 becomes \uXXXX. NUL is one of them: it comes out as the escaped U+0000 form, not as a named sequence. Above ASCII there are exactly two exceptions: U+2028 and U+2029, the Unicode line separators. Raw in a literal they were a syntax error before ES2019 and still break one embedded in a <script> tag, so they come out as \u2028 and \u2029.

Characters above ASCII are deliberately left alone. JavaScript files are UTF-8, and "café" is both valid and readable — escaping it to "caf\u00e9" would only make the literal harder to read.

When you need it

Embedding a snippet, a regex fragment, a log line or a chunk of JSON into a .js or .ts file by hand. Also useful for JSON.parse payloads written inline, where an unescaped quote silently truncates the string.

What it does not do

It escapes for a string literal, not for a template placeholder. If your output lands inside `...${x}...`, the ${ sequence is still interpreted — this tool escapes the backtick but does not neutralise interpolation.

Private by design

Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.

Frequently asked questions

Which quote style is the output for?
All three. Single quotes, double quotes and backticks are escaped, so the result can be pasted between ', " or ` without further editing. That costs a few extra backslashes and saves you from picking the wrong one.
Are accents and emoji escaped?
No. JavaScript source is UTF-8, so é and 😀 are perfectly valid in a string literal and stay readable. If you need a pure ASCII output, the Java escaper does that instead.
What happens to newlines?
They become \n, and carriage returns \r. Control characters below U+0020 that have no named form are written as \u00XX.

Related converters