xxxxxxxxxx
var init_value = 0;
if(init_value > 0){
return true;
} else {
return false;
}
xxxxxxxxxx
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}
xxxxxxxxxx
If - Else Statements
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}
xxxxxxxxxx
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}
if (condition) {
// what to do if condition is met
} else if (condition) {
// what to do if condition is not met
}
xxxxxxxxxx
if (condition1) {
// block of code to be executed if condition1 is true
} else {
// block of code to be executed if the condition1 is false
}
xxxxxxxxxx
if(condition){
//action to take if condition is met
} else if(condition){
//action to take if first condition is not met but there is a second condition
} else{
//actioon to take if all conditions are not met
}
xxxxxxxxxx
if (hour < 18) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
xxxxxxxxxx
function lessThan100(a, b) {
let sum;
if (a + b >= 100) {
result = false;
} else {
result = true;
}
return result;
}
xxxxxxxxxx
/* Shorten if-else by ternary operator*/
const go = "yes"
let race = null
race = go === "yes" ? 'Green Light' : 'Red Light';