English
German

JavaScript Special Text

JavaScript Special Characters

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);

In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called

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);

JavaScript will now output the proper text string: We are the so-called "Vikings" from the north.

Here is another example:

document.write ("You \& I are singing!");

The example above will produce the following output:

You & I are singing!

The table below lists other special characters that can be added to a text string with the backslash sign:

Code Outputs
' single quote
" double quote
& ampersand
\\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

Javascript Tutorial,JavaScript Special Text, JavaScript Special Text example, learn JavaScript Special Text,explain example JavaScript Special Text online free training Javascript Tutorial, Javascript Tutorial example, learn JavaScript Special Text, online tutorial, download tutorial, Javascript Tutorial books, Javascript Tutorial videos, live videos Javascript Tutorial, learn Javascript Tutorial, Javascript Tutorial topic JavaScript Special Text, live training Javascript Tutorial, download free tutorial