JavaScript Escape / Unescape
Turn text into a safe JavaScript string literal (quotes, backslashes, new lines and tabs escaped), or unescape \n, \t, \u0041 and \x41 sequences back to text — in your browser.
Suggested tools
About JavaScript Escape / Unescape
JavaScript Escape converts text into a safe JavaScript string: backslashes, single and double quotes, new lines, carriage returns, tabs, backspaces and form feeds become escape sequences, so the text can be pasted between quotes in your code without breaking it.
Unescape reverses the process and also decodes \uXXXX and \xXX sequences — handy for reading strings from minified code, network responses or logs. Everything runs locally in your browser — the text you paste is never uploaded.
How to use JavaScript Escape / Unescape
- Paste the text, or an escaped JavaScript string.
- Press Escape or Unescape.
- Copy the result into your code.
Key features
- Escapes quotes, backslashes and control characters
- Unicode text kept as-is when escaping (UTF-8 source)
- Decodes \uXXXX and \xXX on Unescape
- Escape and Unescape on one page
Example
Quotes and the line break are escaped so the text fits inside a JavaScript string.
It's a "test" Next line
It\'s a \"test\"\nNext line
When to use JavaScript Escape / Unescape
- Putting multi-line text or quotes into a JavaScript string.
- Reading escaped strings from minified code or network payloads.
- Preparing strings for test files and fixtures.
Tips and common problems
- For data that becomes JavaScript, JSON.stringify is the safest way to create a string literal.
- In template literals (backticks), also escape backticks and ${.
- Non-English text is left as it is — fine for UTF-8 source files.
Frequently asked questions
No. For data embedded in pages, serialise it with JSON.stringify and follow your framework's guidance; escaping by hand for HTML-in-JS contexts is error-prone.
In backtick strings you must also escape ` and ${. This tool targets normal single- or double-quoted strings.
JSON only allows double-quoted strings and has stricter rules. Use JSON Escape when the result must be valid JSON.