Text to escape

Escaped text

Why escape text in JavaScript?

Escaping text in JavaScript is necessary when you want to include special characters in a string. For example, if you want to use a double quote in a string that is already enclosed in double quotes, you need to escape it with a backslash.

Examples of JavaScript escaping

Original text

Hello "World"
Line with 'single' quotes
Tab	and newline
characters
Backslash \ and other special chars

Escaped text

\bHello\b \"\bWorld\b\"\\bnLine\b \bwith\b \'\bsingle\b\' \bquotes\b\\bnTab\b\\btand\b \bnewline\b\\bncharacters\b\\bnBackslash\b \\ \band\b \bother\b \bspecial\b \bchars\b

Common escape sequences in JavaScript

CharacterEscape SequenceDescription
"\"Double quote
'\'Single quote
\\\Backslash
New line\nLine feed
Carriage return\rCarriage return
Tab\tHorizontal tab
Form feed\fForm feed
Backspace\bBackspace
Vertical tab\vVertical tab
Null character\0Null character

When to use JavaScript escaping

  • When creating string literals in JavaScript code
  • When generating JavaScript code dynamically
  • When working with JSON data that contains special characters
  • When storing text that will be evaluated as JavaScript later
  • When displaying code examples that contain JavaScript strings

This tool is useful for preparing text to be used in JavaScript code, JSON data, or any context where JavaScript string escaping rules apply.

Tip:

In modern JavaScript, you can also use template literals (backticks) to avoid escaping quotes: `Hello "world" with 'quotes'`. However, you'll still need to escape backticks and some special characters within template literals.

Related Tools

All Tools

See all available tools