Member-only story
Now lets see Loops and conditions in JavaScript
3 min readOct 7, 2019
…
IF:
Syntax:if (expression) {
Statement(s) to be executed if expression is true
}Example:let x = 5;
if(x>4){
document.write(x)
}
ELSE:
Syntax:if (expression) {
Statement(s) to be executed if expression is true
} else {
Statement(s) to be executed if expression is false
}Example:let x = 5;
if(x>4){
document.write(x)
} else{
document.write("No");
}
ELSE IF:
Syntax:if (expression 1) {
Statement(s) to be executed if expression 1 is true
} else if (expression 2) {
Statement(s) to be executed if expression 2 is true
} else if (expression 3) {
Statement(s) to be executed if expression 3 is true
} else {
Statement(s) to be executed if no expression is true
}Example:let x = 2;
if(x>4){
document.write(x)
} else if (x>1){
document.write("No");
} else{
document.write("maybe")
}
Switch Case:
Syntax:switch (expression) {
case condition 1: statement(s)
break;
case condition 2: statement(s)
break;
...
case condition n: statement(s)
break;
default: statement(s)
}Example:
let a =1
let b= 4…