Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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"
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #ternary #operator
ADD COMMENT
Topic
Name
1+9 =