javascript - Ternary vs. Logical Operators -


Sorry if this is a hoax, then I've only seen the or comparison.

If I want to set the value of a variable based on a condition, where b is always true (no 0, empty, undefined) of Will evaluate, I'm Ternary Operator a? B: c to logical a and amp; Amp; B; C Both of them seem to perform accurate in the same function, although tests at JSPRF are shown slightly later.

What is the purpose of the turner operator if a very similar operation and syntax overcome it at the same job? More curiously, what does do do, which makes it slow?

what would you be 0 or conditional value for some non-zero values Want to set up?

  var x = condition () & amp; Amp; 0 || 1;  

This will not work, because 0 is Farsi.

  var x = condition ()? 0: 1;  

will work because the evaluation does not rely on deep boolean values.


Comments