JavaScript Escape and Unescape

Escape raw text for use inside JavaScript string literals, or decode JavaScript escape sequences back to plain text without eval.

Choose whether the output is intended for a double-quoted string, single-quoted string, or template literal.

Your text is processed in this browser and is not submitted to UnicodeNow.

Processed locally in your browser

This tool works with JavaScript string content. It does not parse complete JavaScript programs, evaluate expressions, decode variables, execute template interpolation, or validate arbitrary source snippets. For strict JSON string escaping, use JSON Escape and Unescape.

Operation

JavaScript string settings

Choose which delimiter rules should be applied while escaping raw text.

When enabled, the output becomes a complete quoted JavaScript string literal.

Use \u{...} for modern code-point escapes or legacy \uXXXX surrogate pairs for older syntax.

Advanced options

Normalization changes the Unicode sequence and is separate from JavaScript escaping.

Input is raw string content, not a complete JavaScript source snippet.

Output is plain text and is never executed or rendered as HTML.

Escape diagnostics

Run the tool to inspect generated or parsed escape sequences.

JavaScript escape and unescape diagnostics
InputCode pointOutputReason or status

What this JavaScript escape and unescape tool does

This tool converts raw text into JavaScript string escape notation, and converts JavaScript escape notation back into decoded text. It is designed for string content: the characters that would appear inside quotes or backticks. It does not execute JavaScript, parse complete programs, evaluate variables, combine string concatenations or run template expressions.

Common JavaScript escape sequences

CharacterEscape
Line feed\n
Tab\t
Carriage return\r
Backslash\\
Double quote\"
Single quote\'
Backspace\b
Form feed\f
Vertical tab\v
Null\0

Escaping double-quoted strings

In a double-quoted string, the double quote, backslash and control characters need escaping. A single quote can remain literal. With delimiters disabled, the output is only the escaped content. With delimiters enabled, the output is wrapped in quotation marks.

Escaping single-quoted strings

Single-quoted strings escape the single quote, backslash and control characters. Double quotes can remain literal. Choose this context when the escaped content will be placed between apostrophes in JavaScript source.

Escaping template literals

Template literals use backticks and support ${...} interpolation. This tool escapes backticks, backslashes and interpolation starts so raw input such as Hello ${name} becomes Hello \${name}. Ordinary dollar signs are preserved.

Unicode escapes in JavaScript

JavaScript supports \u00E9 for one UTF-16 code unit, \u{1F600} for one Unicode code point, and legacy surrogate-pair notation such as \uD83D\uDE00 for emoji. The tool validates surrogate pairs when unescaping and can generate either legacy or code-point escape style when escaping non-ASCII text.

JavaScript strings vs JSON strings

JavaScript string syntax supports forms that JSON does not, including single-quoted strings, template literals, \v, \xHH and \u{...}. For strict JSON string escaping, use JSON Escape and Unescape.

Safe unescaping without eval

Unescape mode uses a dedicated parser for supported escape sequences. It never calls eval(), never creates script elements and never executes input. The parser decodes one syntax layer only, so \\n becomes a literal backslash plus n rather than being recursively decoded into a line break.

Invalid escape sequences

Trailing backslashes, malformed \x escapes, incomplete \u escapes, out-of-range code points and isolated surrogate halves are reported as errors. Malformed escape syntax is not silently preserved in strict mode.

Escaping is not sanitization

JavaScript string escaping does not make text safe for HTML, SQL, URLs, shell commands, CSS, template systems or DOM insertion. Use the correct escaping or encoding for the final context.

Unicode normalization

Normalization is separate from escaping and is off by default. If enabled in Escape mode, normalization is applied before escape sequences are generated and may change the Unicode code-point sequence.

How to use the tool

Choose Escape when you have raw text and need JavaScript string content. Select the string context first: double-quoted, single-quoted, template literal or raw escape notation. Then decide whether the output should include surrounding delimiters. The default keeps delimiters off, which is useful when you only need the content that will be placed inside an existing string literal.

Choose Unescape when you have escape notation such as \n, \x41, \u00E9 or \u{1F600}. The parser decodes one layer of supported string escapes and reports malformed syntax instead of guessing. If you are working with JSON, use the JSON tool because JSON does not allow several JavaScript-specific escape forms.

Use the Unicode character handling selector when you need non-ASCII characters preserved, converted to legacy UTF-16 escapes, or represented with modern code-point escapes. Use output as input only when you intentionally want to run another pass with the current settings.

Privacy and processing

This tool runs in your browser. Your input is not submitted to UnicodeNow, inserted into URLs, saved to localStorage or sessionStorage, or sent through analytics by this page.

Common uses

Example

Input text:

Line 1
Line 2 "UnicodeNow"
C:\Tools
😀

Output for a double-quoted JavaScript string with code-point escapes:

Line 1\nLine 2 \"UnicodeNow\"\nC:\\Tools\n\u{1F600}

The output is escaped string content. Enable “Include surrounding delimiters” to generate a complete quoted string literal.

Template-literal input:

Hello ${name}

Output:

Hello \${name}

Frequently asked questions

What does JavaScript escaping do?

It replaces special characters with escape sequences suitable for JavaScript string syntax.

Is escaping the same as encoding?

No. Escaping represents characters within source syntax; encoding converts data between representations such as UTF-8 or Base64.

How do I escape quotes in JavaScript?

Use \" for double-quoted strings and \' for single-quoted strings.

How do I escape a backslash?

Use \\.

What is \n?

It represents a line-feed character.

What is the difference between \uXXXX and \u{...}?

\uXXXX represents one UTF-16 code unit, while \u{...} represents one Unicode code point.

How are emoji escaped?

Emoji can use a code-point escape such as \u{1F600} or a UTF-16 surrogate pair such as \uD83D\uDE00.

What are surrogate pairs?

Surrogate pairs are two UTF-16 code units used to represent one supplementary Unicode code point.

Can JavaScript escapes be decoded without eval?

Yes. This tool parses supported escape syntax directly and does not execute JavaScript.

Is JavaScript escaping the same as JSON escaping?

No. JSON uses a stricter subset of string escape syntax.

How do template literals differ?

They use backticks, allow literal line breaks, and support ${...} interpolation.

Does this tool execute JavaScript?

No. It treats input as string content or escape notation only.

Does JavaScript escaping sanitize HTML?

No. Escaping for JavaScript strings does not make text safe for HTML, SQL, URLs, shell commands or DOM insertion.

Is my input uploaded?

No. This tool runs in your browser and does not submit input to UnicodeNow.

Related tools

Unicode Escape Converter

Convert text to and from Unicode escape sequences and numeric entities.

DeveloperProcessed locally

PHP Escape and Unescape

Escape and unescape PHP-style single and double quoted strings.

DeveloperProcessed locally

XML Escape and Unescape

Escape and decode XML entities and numeric character references.

DeveloperProcessed locally

URL Encoder and Decoder

Encode and decode URL components, full URLs and form-style strings.

EncodingProcessed locally

Related guides

Unicode vs UTF-8

Unicode defines characters and code points. UTF-8 encodes those code points as bytes for files, databases, web pages, APIs and network messages.

What Is a Unicode Code Point?

Learn what Unicode code points are, how U+ notation works, and how code points differ from glyphs, bytes, code units and visible characters.

Unicode Normalization Explained

Learn NFC, NFD, NFKC and NFKD, canonical and compatibility equivalence, and safe normalization for comparison, search and identifiers.