if else statements javascript code example

Example 1: IF else statement

var age=20;
if (age < 18) {
	console.log("underage");
} else {
	console.log("let em in!");
}

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

var age=20;
if (age < 18) {
	console.log("underage");
} else {
	console.log("let em in!");
}

Example 4: else if javascript

if (condition1) {
  // code to be executed if condition1 is true
} else if (condition2) {
  // code to be executed if the condition1 is false and condition2 is true
} else {
  // code to be executed if the condition1 is false and condition2 is false
}

Example 5: how to use if else statement in javascript

var condition = true; // An example condition for true/false conditions

if (condition == true) {
	console.log('condition is true');  
} else {
	console.log('condition is not true');  
} // Console will output 'condition is true'

Example 6: if then else

if then else

Tags: