EN
JavaScript - escape characters in string
0
points
In this article, we would like to show you escape characters and how to insert them into the string in JavaScript.
Quick solution:
// ONLINE-RUNNER:browser;
const text = 'Hello\tWorld!';
console.log(text); // Hello World!
Practical example
In this example, we use backslash to escape double quotation marks and create a quote inside the text string.
// ONLINE-RUNNER:browser;
const text = "\"This is my quote.\"";
console.log(text); // Hello World!
Escape characters
| escape character | result |
|---|---|
\' |
single quote |
\\ | backslash |
\n | new line |
\t |
tab |
\b | backspace |
\r | carriage return |
\f | form feed |
\ooo | octal value |
\xhh | hex value |