else {document.write ("z is smaller than 8"); }
For the programmer, the above code may be harder to follow BUT for the computer it's more beneficial as much of the unnecessary space characters are eliminated.
Eg: if (z > 8) {
document.write ("z is greater than 8.");
}
else {
A string is enclosed inside
Eg: we declare a variable: helloWorld
we will have to use helloWorld when reffering to the variable at all times
HelloWorld / HELLOWORLD/ HelloWORLd will end up as an ERROR
This grammar rule does NOT apply only to variables.
CASE SENSITIVITY also stands for :
KEYWORDS are ALL LOWERCASE:
Eg: while, for, if , else
METHODS (properties) use CAMEL-BACK naming convention:
1st word is lowercase and each successive 1st letter of the next word is capitalized
Eg: toArray(), lastModified()
etc.
ALL JavaScript statements end in semi-colons ( ; )
EXCEPT for those that don't !
YOU MUST BE AWARE OF 2 THINGS:
1. JavaScript does NOT require a semi-colon at the end of a statement that ends at the end of the line.
If you have one statement per line you don't need semi-colons
Skipping semi-colons however make your code harder to read and to debug
SO
YOU SHOULD USE SEMICOLONS ANYWAY
Eg: function sample( ) {
var z = 1;
var x = 2;
var y = 3;
return;
x + y + z;
}
Always be careful where you break your statements if you break them across multiple lines.