JavaScript Escape / Unescape
Escape and unescape JavaScript strings - convert special characters like \n, \t, \r, \", \\ to escape sequences
Input
Output
What Is JavaScript Escape?
In JavaScript strings, certain characters must be escaped so they can be represented safely: single quotes, double quotes, backslashes, newlines, tabs, carriage returns, and more. Escaping converts them to sequences like \', \", \\, \n, \t, \r. Unescaping does the reverse: it turns those sequences back into the actual characters.
This tool has two modes: Escape and Unescape. Toggle between them at the top. Both run in your browser; nothing is sent to a server.
How to Use This Tool
Choose Mode
Select Escape to convert special characters to escape sequences, or Unescape to convert them back.
Paste Input
Paste your text into the left editor. You can paste a raw string or an already-escaped string. Use Sample or Upload if needed.
Copy Result
The right panel updates automatically. Use <strong>Copy</strong> or <strong>Download</strong> to get the result. For formatting JavaScript code, try JS Formatter.
JavaScript Escape Examples
Escaping converts special characters to escape sequences. Example:
Raw input (with newline and tab)
Escaped output
When Escaping Matters
When embedding strings inside JavaScript code, template literals, or JSON-like structures, certain characters must be escaped to avoid syntax errors. For example, a single quote inside a single-quoted string must be escaped as \'. When building strings programmatically, JavaScript handles some escaping automatically, but manual escaping is needed when working with raw text, log data, or API responses.
Unescaping is useful when you receive a pre-escaped string and need to get the actual readable text. For JSON-specific escaping, try the JSON Escape tool.
Frequently Asked Questions
What characters get escaped?
JavaScript escape handles: \\ (backslash), \' (single quote), \" (double quote), \n (newline), \r (carriage return), \t (tab), \0 (null), \v (vertical tab), \f (form feed).
How is this different from JSON Escape?
JSON escape only escapes characters required by the JSON spec (primarily " and \ and control chars). JavaScript escape also handles single quotes (\') and other JS-specific sequences.
Is my data sent anywhere?
No. Processing runs entirely in your browser.
Can I use this for template literals?
This tool escapes for traditional string literals. Template literals (backtick strings) use \` and \$ — those are not included here. For template literals, escape only the backtick and dollar-brace sequences manually.
When would I need to unescape?
When you receive an escaped JavaScript string (e.g. from a log, a database dump, or serialized code) and need to see or use the raw text.
Related Tools
JavaScript string escape sequences are defined in the ECMAScript specification. MDN String documentation covers string literals and escape sequences. For JSON escaping rules see RFC 8259.