The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.
Look at the following JavaScript code:
var txt="We are the so-called "Vikings" from the north.";
document.write(txt); |
To solve this problem, you must place a backslash (\) before each double quote in "Viking". This turns each double quote into a string literal:
var txt="We are the so-called \"Vikings\" from the north.";
document.write(txt); |
Here is another example:
document.write ("You \& I are singing!");
|
You & I are singing!
|
Code
|
Outputs
|
\'
|
single quote
|
\"
|
double quote
|
\&
|
ampersand
|
\\
|
backslash
|
\n
|
new line
|
\r
|
carriage return
|
\t
|
tab
|
\b
|
backspace
|
\f
|
form feed
|
No comments:
Post a Comment
Please write your view and suggestion....