1(lemons) ? alert("please give me a lemonade") : alert("then give me a beer");
1condition ? doThisIfTrue : doThisIfFalse
2
31 > 2 ? console.log(true) : console.log(false)
4// returns false
1//ternary operator syntax and usage:
2condition ? doThisIfTrue : doThisIfFalse
3
4//Simple example:
5let num1 = 1;
6let num2 = 2;
7num1 < num2 ? console.log("True") : console.log("False");
8// => "True"
9
10//Reverse it with greater than ( > ):
11num1 > num2 ? console.log("True") : console.log("False");
12// => "False"
1var variable;
2if (condition)
3 variable = "something";
4else
5 variable = "something else";
6
7//is the same as:
8
9var variable = condition ? "something" : "something else";
1condition ? expression1 : expression2
2// Will return expression1 if condition = true and expression2 if condition != true