📜 JavaScript Escape/Unescape

Escape and unescape JavaScript string literals. Handle quotes, backslashes, and special chars.

About the JavaScript Escape/Unescape tool

This tool escapes text into a form safe to embed inside a JavaScript string literal, and reverses the operation. Useful when generating JavaScript code, embedding user-provided text in templates, or sanitizing inputs for eval-free string assembly.

Escape sequences handled

  • \ → \\ (backslash)
  • ' → \' (single quote)
  • " → \" (double quote)
  • newline → \n
  • carriage return → \r
  • tab → \t

Frequently asked questions

Why is backslash escaped first? Because every other replacement introduces new backslashes. Escaping backslash first prevents double-escaping.

What about Unicode characters? Unicode code points above U+007F are preserved as-is. To convert them to \uXXXX sequences, use a dedicated Unicode escape tool.

Does the unescape pass support \uXXXX? Yes — the unescape handler recognizes \b, \f, \v, \0, \uXXXX, \xXX, and unknown escapes are passed through.