+ 1
conditional (Ternary) operators: (I don't get it) Please Help me?!
In JavaScript under the above title, you will see a statement: variable = (condition) ? value1 : value2 Is it that the condition is saying IF the condition is TRUE, then value1 is output as the answer, otherwise, condition MUST BE FALSE, so value2 is the output. Do I have it right? This is the only way I can make sense of it. I hope that it is correct, but if not, can someone please help me understand? I would greatly appreciate it. ~MJC
4 Answers
+ 4
Yes you're totally correct!
alert(true? "Yas!" : "Boo~"); // Output: Yas!
+ 4
You're welcome Michael! đ
Please mark the best answer that you find useful to help others when they found this question in future.
+ 2
cond ? executes if true : executes if false
+ 1
@Zephyr Koo -- Oh, good. I am finally getting the hang of it. Thanks for your help and for the example. I appreciate it. đđ€đ