Java Reference
In-Depth Information
JavaScript Grammar
The syntax used by JavaScript is known as a C-style syntax, which is similar to the one used
by Java.
A JavaScript program is made up of a series of statements . Each statement ends with a new
line or semicolon.
Here is an example of two statements, one on each line:
a = "Hello World!"
alert(a)
This example could also be written as follows, using semicolons at the end of each state-
ment:
a = "Hello World!";alert(a);
There's no need to actually use a semicolon to terminate a statement because JavaScript in-
terpreters use a process called Automatic Semicolon Insertion (ASI) . This will attempt to
place semicolons at the end of lines for you; however, it can be error-prone and cause a num-
ber of automated services such as code minifiers and validators to not work properly.
For this reason, it's considered best practice to combine the two and write each statement on
a new line, terminated by a semi-colon, like so:
a = "Hello World!";
alert(a);
A block is a series of statements that are collected together inside curly braces:
{
// this is a block containing 2 statements
var a = "Hello!";
alert(a);
}
Search WWH ::




Custom Search