js if ? code example

Example 1: js if else

If - Else Statements
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}

Example 2: if statement javascript

const randomObject = 5;
if(randomObject < 2) {
console.log("The Random Object has a value more than 2");
}
else {
console.log("The Random Object has a value less than 2");
}

Example 3: javascript if else

/* Shorten if-else by ternary operator*/
const go = "yes"
let race = null

race = go === "yes" ? 'Green Light' : 'Red Light';

Tags:

Php Example