ternary operator javascript w3schools code example
Example 1: javascript ternary operator
//ternary operator syntax and usage:
condition ? doThisIfTrue : doThisIfFalse
//Simple example:
let num1 = 1;
let num2 = 2;
num1 < num2 ? console.log("True") : console.log("False");
// => "True"
//Reverse it with greater than ( > ):
num1 > num2 ? console.log("True") : console.log("False");
// => "False"
Example 2: ternary operator if javascript
condition ? exprIfTrue : exprIfFalse
Example 3: js !==
var x = 5;
// === equal value and equal type
// e.g. 1.
x === 5 returns true
// e.g. 2.
x === "5" returns false
// !== not equal value or not equal type
// e.g. 1.
x !== 5 returns false
// e.g. 2.
x !== "5" returns true
// e.g. 3.
x !== 8 returns true