JavaScript & Browser

JavaScript String Escaper

Turn any text into a safe JavaScript string literal, or decode an escaped literal back into readable text. Handles quotes, newlines, control characters, and Unicode — everything runs in your browser, so your input never leaves the page.

Runs in your browser v1.0.0

Direction & options

live
What do you want to do?

Choose the quote that will wrap the literal, or bare escapes to paste the body yourself. <script> stays safe because nothing is rendered as HTML.

Input

text

Everything is processed locally. Ctrl/ Cmd + Enter copies the result.

Output

literal

What gets escaped

Escaping protects a backslash, the surrounding quote character, and the short escapes \n, \r, \t, \b, \f, and \v. Remaining control characters use \xHH, and the JavaScript line/paragraph separators \u2028 and \u2029 are always escaped. Enable the Unicode option to turn every non-ASCII character into a \uXXXX escape when you need pure ASCII output.

Unescaping understands the full JavaScript string grammar: \xHH, \uHHHH, \u{...}, line continuations, and identity escapes. Legacy octal escapes are rejected with an explanation because they are invalid in strict mode.