ternary operator w3schools code example

Example 1: less than or equal to javascript

if(a <= 5){
   yourFunction();
}

Example 2: ternary operator javascript

// ternary operators are frequently used as a shorter cleaner if statement
// condition ? exprIfTrue : exprIfFalse

let age = 15;
let canDrive = age >= 16 ? 'yes' : 'no';
// canDrive will be 'no'
// the condition will be age > 16 which is false so canDrive will equal exprIfFalse

// this ternary is the same as this if else statement
let age = 15;
let canDrive;
if (age >= 16) {
    canDrive = 'yes';
} else {
    canDrive = 'no';
}

// canDrive will be 'no' because 15 is less than 16

Example 3: less than equal to in javascript

| <= | less than or equal to |	x <= 8 | true |

Example 4: === javascript

// ===	means equal value and equal type
var x = 5

// true
x === 5

// false
x === "5"