Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
Because ( a && b ) give the last... because to know the result of the conditionnal expression, you need to evaluate all operande since one is false, and return the last evaluated instead a true/false value. As in JS, all that's non-zero ( included negatives numbers ), empty, none, undefined, is false, everything else is true. So for any value of a and b different of zero, b is returned :P ( but 0 will be returned if encountered, because all expression is false if only one is false ) Usually, you encounter rather ( a || b ), as it returns the first value to be true ^^ ( because the entire expression is true if at least on element is true )
17th Feb 2017, 8:46 PM
visph
visph - avatar