JavaScript Grammar
if
if (condition) {
//when condition is true,execute it.
}
if else
if (condition) {
//when condition is true,execute it.
}else {
//when condition is false,execute it.
}
if…else
if (condition1) {
//when condition1 is true,execute it.
}else if(condition2) {
//when condition2 is true,execute it.
}
......
else{
//when all condition is false,execute it.
}
switch
switch(c1) {
case 1: //code one
break;
case 2: //code two
break;
default: //code other
}
- example
function f1() {
var d = new Date(