JavaScript Special Characters And Guidelines
Insert Special Characters
Javascript Is Case Sensitive
White Space
Break up a code Line
you ca add special characters to a text string by using the back-slash character.
Insert Special Characters
The backslash (\) is used to insert aposrophes,new lines,quotes, and other special characters into a text string.
var txt="we are the so-called "vikings" from the north";
document.write(txt);
result: we are the so-called
To solve this problem, you must place a backslash(\) before each double quote in "vikings".
THis turns each double quote into a string.
var txt="we are the so-called \"vikings\" from the north";
document.write(txt);
result:we are the so-called "vikings" from the north
document.write("you \& i are singing");
result: 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
Javascript is case sensitive
White space
Javascript ignors extra spaces.
you can add white space to your script to make it more readable.
name="Hege";
name = "Hege";
Break up a code line
Text in code statements contained within quotes is called "string literal".
A string literal may not be broken across lines except by inserting the backslash character(\) at the point where you want to break the string:
document.write("Hello \
World");
following will generate "unterminated string literal" script error
document.write("Hello
World");
Another option is to use the concatenate operation(+) to break the string:
document.write("Hello"+
"world!");
code statements may be broken across lines, but the backslash character must not be used in this case.
document.write
("Hello"
+
"world!"
);
break code statements or string litterals across lines only when the length of the line or literal make it difficult to read.
you cannot break up a code line like this
document.write \
("Hello World");
Insert Special Characters
Javascript Is Case Sensitive
White Space
Break up a code Line
you ca add special characters to a text string by using the back-slash character.
Insert Special Characters
The backslash (\) is used to insert aposrophes,new lines,quotes, and other special characters into a text string.
var txt="we are the so-called "vikings" from the north";
document.write(txt);
result: we are the so-called
To solve this problem, you must place a backslash(\) before each double quote in "vikings".
THis turns each double quote into a string.
var txt="we are the so-called \"vikings\" from the north";
document.write(txt);
result:we are the so-called "vikings" from the north
document.write("you \& i are singing");
result: 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
Javascript is case sensitive
White space
Javascript ignors extra spaces.
you can add white space to your script to make it more readable.
name="Hege";
name = "Hege";
Break up a code line
Text in code statements contained within quotes is called "string literal".
A string literal may not be broken across lines except by inserting the backslash character(\) at the point where you want to break the string:
document.write("Hello \
World");
following will generate "unterminated string literal" script error
document.write("Hello
World");
Another option is to use the concatenate operation(+) to break the string:
document.write("Hello"+
"world!");
code statements may be broken across lines, but the backslash character must not be used in this case.
document.write
("Hello"
+
"world!"
);
break code statements or string litterals across lines only when the length of the line or literal make it difficult to read.
you cannot break up a code line like this
document.write \
("Hello World");
No comments:
Post a Comment