when to use conditional statement in javascript code example

Example 1: javascript how to do if else

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

Example 2: how to make an if statement in javascript

if(condition1) { //runs if the condition is true
  //type what you want to happen if the condition is true
}else if (condition2) {
  //type what you want to happen if the condition is true
} else { //If no condition is true it will run this
  //type what you want it to do
}

Example 3: javascript conditional

// example:
age >= 18 ? `wine` : `water`;

// syntax:
// <expression> ? <value-if-true> : <value-if-false>

Example 4: how to shorten conditional statements javascript

var canDrive = age > 16 ? 'yes' : 'no'

Tags: