JavaScript Escape String Online
Turn any text into a safe JavaScript string literal. Choose single quotes, double quotes or a template literal, and quotes, backslashes, line breaks and control characters are escaped correctly. Nothing is uploaded.
How to use JavaScript Escape String on KickSolve
Three quick steps, no account needed.
Why choose KickSolve
Built for speed, privacy and accurate results.
About JavaScript Escape String on KickSolve
What it does and how to get the best results.
What is a JavaScript string escape?
Inside a JavaScript string some characters would end the string or change its meaning, such as the quote that surrounds it, a backslash or a new line. A backslash escape such as \', \\ or \n lets you write them safely.
Characters this tool escapes
| Character | Escaped as |
|---|---|
| Backslash | \\ |
| The chosen quote | \' or \" or \` |
| New line, return, tab | \n \r \t |
| Backspace, form feed, vertical tab | \b \f \v |
| Null and other control characters | \0 and \xHH |
| Line and paragraph separators | \u2028 \u2029 |
| Non-ASCII, when turned on | \uXXXX |
Single quotes, double quotes and template literals
Pick the quote you will use around the string. In a single-quoted string only \' needs escaping, in a double-quoted string only \". In a template literal with backticks the tool also escapes ${ so that it is not read as an expression.
Is this the same as the JavaScript escape() function?
No. The old global escape() function turns text into percent codes for URLs and is deprecated. This page creates a valid string literal. For URLs use encodeURIComponent.
Safe text inside an HTML script tag
The characters </script> inside a script string can end the script early. Turn on Escape </ for HTML scripts and the tool writes <\/script> instead.
JavaScript Escape String examples
Real input and output so you can see exactly what changes.
Apostrophe in a single-quoted string
Input
It's "quoted"Output
It\'s "quoted"Windows path
Input
C:\Users\meOutput
C:\\Users\\meTemplate literal (backtick mode)
Input
Total: ${price}Output
Total: \${price}When do you need to escape a JavaScript string?
Common reasons people use this page.
Privacy, limits and browser support
What happens to your data and what to expect.
- How it works: with KickSolve, the conversion runs in your browser with JavaScript. Your text is not sent to a server and is not stored.
- Limits: there is no limit set by us. Very large text, many megabytes, depends on your device memory.
- Browsers: current Chrome, Edge, Firefox and Safari on desktop and mobile.
Read the KickSolve privacy policy for details about the site itself.
Frequently asked questions
Quick answers.
How do I escape a string in JavaScript?
Put a backslash before the quote that surrounds the string, double any backslash, and write new lines as \n. This page does all of it as you type.
How do I escape single quotes in JavaScript?
Choose Single quote style. Every apostrophe becomes \' and everything else is left as it is.
How do I escape a backtick or ${ }?
Choose Backtick. The tool escapes backticks and the ${ sequence so a template literal does not run code by mistake.
How do I escape a new line?
A line break is written as \n and a tab as \t. Both are handled automatically.
Should I escape non-ASCII characters?
Usually not, because JavaScript supports Unicode. Turn on Escape non-ASCII only for ASCII-only files, and each character becomes a \uXXXX code.
Is it the same as escape() or encodeURIComponent?
No. Those encode text for URLs. This tool creates string literal escapes for source code.
Is my text uploaded anywhere?
No. Everything runs in your browser.
Is it free?
Yes. It is free and needs no signup.
More free tools from KickSolve
Related string and developer tools.