how to call a function in an if statement javascript code example
Example 1: if else javascript
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
Example 2: using if statements in javascript
if (expression) {
Statement(s) to be executed if expression is true
} else {
Statement(s) to be executed if expression is false
}
Example 3: JavaScript if else and else if
if (condition) {
}
if (hour < 18) {
greeting = "Good day";
}
if (condition) {
} else {
}
if (hour < 18) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
Example 4: how to use if else statement in javascript
var condition = true;
if (condition == true) {
console.log('condition is true');
} else {
console.log('condition is not true');
}