JavaScript string escape
Pick the quote type you will wrap the string in and get text ready to paste into code.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter text, quote style and escape non-ascii as \uxxxx.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
Backslash becomes \\, newline \n, tab \t, and the chosen quote gets a backslash. Control characters become \xHH and U+2028/U+2029 become \u2028/\u2029. In ASCII mode every character above 126 becomes \uXXXX in UTF-16 units.
Example
Inputs: Quote style = Double ", Escape non-ASCII as \uXXXX = no. Result: Escaped string: قال: \"مرحبا\"\nسطر ثان.
قال: "مرحبا" سطر ثان
قال: \"مرحبا\"\nسطر ثان
Limits and caveats
- Output is for JavaScript strings; inside an HTML script tag you must also break up </script.
- In ASCII mode emoji are written as surrogate pairs such as \uD83D\uDE00.
Questions about this tool
Why escape the quote character?
An unescaped quote ends the string early and breaks the code.
Why turn Arabic into \uXXXX?
It keeps the text safe if the file is saved or sent in a non-UTF-8 encoding; the browser shows the same letters.
Why is ${ escaped in template literals?
${ starts an embedded expression in a template literal; escaping it keeps it as plain text.
