inserting special characters
Backslashes are used to insert ellipses, line breaks, quotation marks, and other special characters in a text string.
Take a look at the following JavaScript code:
"Vikings"
From the north. " document.write (TXT)
In JavaScript, strings start or end with single or double quotation marks. This means that the above string will be truncated as: We are the so-called.
To solve this problem, you must precede the quotation marks in the "Viking" with the backslash (\). This allows you to convert each double quotation mark to a literal string.
\"Vikings\"
From the north. " document.write (TXT)
Now JavaScript can output the correct text string: We are the so-called "Vikings" from the north.
This is another example:
\&
Me is singing! ")
The above example produces the following output:
You & Me is singing!
The following table lists the remaining special characters that can be added to a text string using a backslash:
Code |
Output |
\‘ |
Single quotation marks |
\" |
Double quotes |
\& |
and number |
\\ |
Back slash |
\ n |
Line break |
\ r |
Carriage return character |
\ t |
Tabs |
\b |
Backspace |
\f |
Page break |
JavaScript Special symbols