Bytelify

JavaScript Escape

Escape text for use inside a JS/JSON string literal, live as you type, in either direction.

Runs in your browser, nothing sent
javascript-escape

Escapes text the way it would appear inside a JS/JSON string literal (quotes, backslashes, newlines) โ€” type in either field, both directions update live. Runs entirely in your browser.

Need the opposite? HTML Escape

What is JavaScript Escape?

Type text and see it escaped the way it would need to appear inside a JavaScript or JSON string literal (quotes, backslashes, and newlines escaped). Type in either field and both directions update live. Handy when hand-building a string literal that contains quotes, backslashes, or line breaks: pasting user-generated text into a JS template, a JSON payload, or a config file without it breaking the surrounding syntax. Everything runs in your browser as you type.

How to Use the JavaScript Escape Tool

  1. 1

    Type or Paste the Text: Enter any text, including quotes, backslashes, or multi-line content.

  2. 2

    Read the Escaped Result Instantly: The JS/JSON-safe escaped string appears automatically as you type.

  3. 3

    Copy the Result: Use the copy button to copy the escaped string for use in code or a config file.

What Gets Escaped and Why

A JavaScript or JSON string literal is wrapped in quotes, so a literal quote character inside the string would end it early unless it's escaped. Backslashes need escaping for the same reason: a backslash starts an escape sequence, so a literal one has to be written as \\ to be read back correctly. Newlines can't appear as a raw line break inside a single-line string literal either, so they're written as \n. This tool produces the same escaping JSON.stringify() would generate, just without the surrounding quotes, so the result drops straight into a string literal you're already writing.

Example

JAVASCRIPT
Input:
He said "hi"
Bye

Escaped:
He said \"hi\"\nBye

The quote characters become \", and the line break between "hi" and "Bye" becomes the two-character sequence \n. Both are now safe to drop inside a single-line "..." string literal.
FAQs

Frequently Asked Questions

Common questions about JavaScript Escape.

Yes, under the hood. It produces the exact escaping JSON.stringify would, minus the surrounding quotes, so you can drop the result straight into your own string literal.

Yes, this tool works in both directions; type or paste into either field and the other updates instantly.

No, the output is the escaped content only, without the wrapping quotes, so you can drop it directly inside whichever quote style (" or ') you're already using in your code.

Yes, Bytelify's JavaScript Escape tool is free with no account or sign-up required.

No. The escaping runs entirely client-side in your browser, so nothing you type is sent anywhere.