|
| ESCAPING CHARACTERS IN JAVASCRIPT
Certain characters after a backlash \ have a special effect in the javascript code. This is referred to as the escape sequence.
Some of these characters are:
\n
Characters after it start on a new line.
Example:
var string="Go on, make \n my day";
alert(string);
The above outputs:
Go on, make
my day
\t
Horizontal tab space immediately after.
Example:
var string="Go on, make\t my day";
alert(string);
The above outputs:
Go on, make my day
\r
Carriage return immediately after.
Example:
var string="Go on, make\r my day";
alert(string);
The above outputs:
Go on, make
my day
\'
Single quote. Useful in single quoted strings without causing the string to terminate prematurely.
Example:
var string='Go on, \'make my\' day';
alert(string);
The above outputs:
Go on, 'make my' day
\"
Double quote. Useful in double quoted strings without causing the string to terminate prematurely.
Example:
var string="Go on, \"make my\" day";
alert(string);
The above outputs:
Go on, "make my" day
\\
Single backslash. Allows you to literally insert a backslash character.
Example:
var string="Go on, \\make my day";
alert(string);
The above outputs:
Go on, \make my day
Other special characters:
\f - form feed
\b - backspace
 |
|
|