JavaScript String Encoder
Escape special characters for safe use in JS strings, or decode escape sequences back to literal text
Drop in a raw string and get a properly escaped version ready for your JavaScript code — quotes, backslashes, newlines, unicode, all handled in one click. Pick your quote style, toggle HTML entity encoding for XSS-safe output, or decode an already-escaped string back to readable text. And everything runs in your browser. Nothing gets uploaded.
How to Use
Paste your text into the input panel — raw text to encode, or an escaped JS string to decode.
Choose options — quote style (single, double, or backtick), unicode escape for non-ASCII characters, and HTML entity encoding for XSS prevention.
Click Encode to escape special characters for safe use in JavaScript strings, or Decode to reverse escape sequences back to literal characters.
Copy or Download the result. Use Ctrl+Enter as a keyboard shortcut to encode.
Frequently Asked Questions
What characters does the JavaScript string encoder escape?
The encoder escapes all characters that have special meaning in JavaScript strings: backslashes (\), single quotes ('), double quotes ("), backticks (`), newlines (\n), carriage returns (\r), tabs (\t), backspace (\b), form feed (\f), and null bytes (\0). Optionally, it can also escape non-ASCII characters to \uXXXX or \u{XXXXX} sequences and encode HTML-sensitive characters (< > &) for XSS prevention.
What is the difference between Encode and Decode mode?
Encode mode takes raw text and converts special characters into their JavaScript escape sequences, making the text safe to embed inside a JS string literal. Decode mode does the reverse — it takes a string containing escape sequences like \n, \t, \\, \uXXXX and converts them back to their literal characters so you can read the original text.
How does the quote style option affect encoding?
The quote style determines which quote character gets escaped. If you select single quotes, only single quotes (') are escaped while double quotes and backticks are left as-is. If you select double quotes, only double quotes (") are escaped. Backtick mode escapes backticks (`) and also escapes the dollar-brace sequence (${) to prevent template literal expression injection. This way your encoded string is safe for the specific JS string delimiter you plan to use.
What does the HTML entities option do?
When enabled, the HTML entities option encodes the characters <, >, and & using their JavaScript unicode escape sequences (\u003C, \u003E, \u0026). This prevents Cross-Site Scripting (XSS) attacks when the JavaScript string is embedded in an HTML page, as it stops browsers from interpreting these characters as HTML tags or entities.
Is my data secure when using this tool?
Yes, 100%. All encoding and decoding happens entirely in your browser using JavaScript. Your text is never uploaded to any server, never stored, and never leaves your device. You can verify this by disconnecting from the internet — the tool works fully offline.