NV ToolkitFormat · Validate · Convert

Escape / Unescape

JavaScript Escape / Unescape

Make any text safe inside a JavaScript string literal — quotes, backslashes, newlines and control characters handled both ways.

In short

Escape and unescape JavaScript strings online: quotes, backslashes, newlines, tabs and control characters — both directions, instantly, in your browser.

By NaveenKumar T · Updated

Learn: Escaping vs Parameterised Queries

  • Escape & unescape in one tool
  • Handles every special character
  • Instant as you switch modes

Runs entirely in your browser — nothing you paste or open here is uploaded, logged, or stored.How we handle data →

Example

JavaScript Escape: input and output

A two-line tooltip being embedded in a double-quoted JavaScript string.

Text
Press "Ctrl+\" to split the pane.
Tip:	set ~/.config/app (or %APPDATA%\app on Windows) — it's 'safe' → ✔
JavaScript string content
Press \"Ctrl+\\\" to split the pane.\nTip:\tset ~/.config/app (or %APPDATA%\\app on Windows) — it's 'safe' → ✔

The double quotes, both backslashes, the tab and the line break gained escapes; the single quotes, the em dash, the arrow and the check mark were passed through unchanged.

Learn more

JavaScript escaping rules

A JavaScript string literal ends at its first unescaped quote and cannot contain raw newlines — so embedding arbitrary text means escaping: \" for quotes, \\ for backslashes, \n \r \t for whitespace control, and \uXXXX for control characters. This tool applies exactly those rules, producing a string you can paste between quotes in any .js file.

Unescape mode interprets the full escape grammar — including \xNN and \uXXXX forms — turning copied string literals (from minified bundles, logs, or JSON) back into readable text. Malformed sequences like a dangling backslash are reported rather than silently mangled.

Help

Frequently asked questions

Everything you need to know about the JavaScript Escape.

01How do I escape or unescape JavaScript here?

Paste your text, pick Escape or Unescape in the Mode select, and press Convert. Escape adds backslashes before quotes, backslashes and control characters so the result drops into a JavaScript string literal; Unescape parses the full escape grammar back to plain text.

02What's the difference between this and JSON escape?

JSON's escape set is a strict subset: JSON requires \u for all control characters and forbids \x escapes and single-quote escaping. Text escaped here works in JavaScript source; for data interchange (APIs, config files), prefer the JSON Escape tool so the result is valid in both worlds.

03Does JavaScript escape convert non-ASCII text to \uXXXX, and does it escape single quotes?

Neither. Accented letters, symbols and emoji pass through as-is — JavaScript source is Unicode and every modern bundler reads UTF-8 — so only double quotes, backslashes, tabs, newlines and other control characters gain a backslash. Single quotes are left untouched too, which means the output is meant for a double-quoted literal; inside a single-quoted or template literal, escape ' or ` yourself. If you need an ASCII-only literal with \u sequences, the Java Escape tool applies that convention.

04Should I just use JSON.stringify to escape a string for JavaScript?

JSON.stringify works for a double-quoted literal — it escapes quotes, backslashes and control characters the same way — so for that one case it's a fine shortcut. It doesn't help with backticks or `${`, though: neither is special to JSON, so a value headed into a template literal still needs this tool's output plus those two characters escaped by hand.

05Is the output safe to put inside an HTML <script> tag?

A literal </script> inside a string still closes the surrounding script element on its own, because the HTML parser looks for that sequence before JavaScript ever runs — escaping quotes and backslashes doesn't touch it. Escape < as \u003c as well, which is what this site's own JSON-LD renderer does before it inlines untrusted text into a page.

Keep working

Related tools

Learn the format

Related guides

All guides →