HTML and CSS Reference
In-Depth Information
The following line is incorrect:
var name = "Ellie" document.write("Hi "+name); <- wrong, two statements
It should be:
var name = "Ellie" ; document.write("Hi " + name); <- semicolon needed
to separate two
statements on the
same line
If the statements are grouped in a block of curly braces, they act as a single statement.
if ( x > y) { statement; statement; } <- Statements enclosed in curly
braces act as a single
statement
2.2.4 Comments
A comment is text that describes what the program or a particular part of the program
is trying to do and is ignored by the JavaScript interpreter. Comments are used to help
you and other programmers understand, maintain, and debug scripts. JavaScript uses
two types of comments: single-line comments and block comments.
Single-line comments start with a double slash:
// This is a comment
For a block of comments, use the /* */ symbols:
/* This is a block of comments
that continues for a number of lines
*/
2.2.5 The <script> Tag
JavaScript programs must start and end with the HTML <script> and </script> tags,
respectively. Everything within these tags is considered JavaScript code, nothing else.
The script tag can be placed anywhere within an HTML document. If you want the Java-
Script code to be executed before the page is displayed, it is placed between the <head>
and </head> tags. This, for example, is where function definitions are placed (see Chap-
ter 7, “Functions”). If the script performs some action pertaining to the body of the doc-
ument, then it is placed within the <body> and </body> tags. A document can have
multiple <script> tags, each enclosing any number of JavaScript statements.
 
 
 
Search WWH ::




Custom Search