JavaScript Escape / Unescape
Escape any text into a safe JavaScript string literal, or unescape a JS string back to plain text — all in your browser.
Last updated: May 30, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is JavaScript Escape / Unescape?
JavaScript Escape / Unescape converts text to and from the escaped form required inside JavaScript string literals. When you paste raw text, the tool adds the backslash sequences that JavaScript needs — \\ for a literal backslash, \" for a double-quote, \n for a newline, \r for a carriage return, and \t for a tab — so the result can be pasted straight into JS source code. Unescape reverses the process, decoding \\n, \\t, \\uXXXX and other sequences back to the original characters.
Everything runs locally in your browser, so code and secrets never leave your machine.
How to Use JavaScript Escape / Unescape
Paste your text into the input box
Choose Escape to build a JS string literal, or Unescape to decode one
Optionally enable \uXXXX escaping for non-ASCII characters
Copy the output into your JavaScript source code
Common Use Cases
- Embedding a multi-line user message into a JavaScript string safely.
- Escaping a Windows file path (backslashes) for use in a JS string.
- Decoding an escaped JavaScript string from a log file or API response.
- Escaping user input before building a dynamic script tag or eval expression.
- Converting non-ASCII characters to \uXXXX for ASCII-only JavaScript source.
Example Input and Output
Escape a Windows path and a message with special characters for a JavaScript string literal.
C:\temp\log.txt
Line "two" TabbedC:\\temp\\log.txt\nLine \"two\"\tTabbedHow This Tool Works
The tool scans your text character by character, replacing special characters with their JavaScript escape sequences (or reversing that mapping when unescaping), entirely in the browser using the shared code-escape engine.
Technical Stack
JavaScript string escapes
JavaScript string literals support \\, \" and \', \n, \r, \t, \b, \f, \uXXXX, and \xXX (hex escape). In template literals (backticks), only \` and \${ need special treatment.
Privacy
Processing is fully client-side — nothing is sent to a server.
Frequently Asked Questions
Which characters does it escape?
Escaping emits \\ \" \n \r \t \b \f and optionally \uXXXX for non-ASCII code points. Unescaping also handles \' and any \uXXXX sequences.
Does it handle template literals (backticks)?
No. Template literals have their own rules (backtick and ${ need escaping). This tool targets standard double-quoted or single-quoted JS string literals.
Is my input sent to a server?
No. All escaping and unescaping runs entirely in your browser using JavaScript string operations.
What is the difference between this and the String Escape tool?
The String Escape tool supports multiple formats (JSON, HTML, URL, JavaScript). This page is a focused, JavaScript-only experience with a cleaner interface and more specific examples and documentation.
Related Tools
String Escape / Unescape
Escape or unescape strings for JSON, JavaScript, HTML, URL, CSV, and RegEx contexts — instantly.
JSON Escape / Unescape
Escape strings for use inside JSON values or unescape JSON-encoded strings back to readable text.
HTML Escape / Unescape
Escape and unescape HTML special characters (&, <, >, ", ') on a single page.
URL Encoder/Decoder
Encode and decode URL strings with special characters.
C# Escape / Unescape
Escape or unescape text for C# string literals in your browser. Free, no signup, runs locally.
Java Escape / Unescape
Escape or unescape text for Java string literals in your browser. Free, no signup, runs locally.

