What is JavaScript String Escape?
JavaScript String Escape converts special characters in text into their escaped equivalents so the string can be safely embedded in JavaScript code or used in places where special characters would cause syntax errors or unexpected behavior. Characters like quotes, backslashes, newlines, tabs and carriage returns are converted into their backslash-escaped forms (such as \" for quotes and \n for newlines). The tool runs entirely in your browser with nothing uploaded, making it safe for any text.
How JavaScript String Escape works
When JavaScript encounters special characters in a string, they must be escaped with a backslash to prevent errors. This tool automatically escapes the five most common problem characters:
- Backslashes:
\becomes\ - Double quotes:
"becomes\" - Newlines: (line break) becomes
\n - Carriage returns: becomes
\r - Tabs: becomes
\t
Worked example — escaping a quote:
Input: He said "hello"
Output: He said \"hello\"
Now the string can be safely written in JavaScript code like var msg = "He said \"hello\""; without causing a syntax error.
How to use
- Enter or paste your text in the input box.
- The JavaScript String Escape-encoded result appears instantly in the output.
- Click Copy to use the encoded value.
Common uses
- Preparing text to embed in JavaScript strings without breaking syntax.
- Escaping user input or API responses for safe JavaScript code generation.
- Converting multi-line text into single-line escaped strings for data attributes or configs.
- Debugging string values that contain quotes, backslashes or special whitespace.
- Building template strings or dynamic code that includes raw text with special characters.