javascript - What is the difference between these comparisons using || and , -


what difference between these 2 statements. different results when use these interchangeably. hoping explain me. whats difference between, this...

else if ( ( elecshow ==2,3,4,5,6,8,9,10,16 ) ) 

and this...

else if ( ( elecshow ==2 ) || ( elecshow ==3 ) || ( elecshow ==4 ) || ( elecshow ==5 ) || ( elecshow ==6 ) || ( elecshow ==8 ) || ( elecshow ==9 ) || ( elecshow ==10 ) || ( elecshow ==16 ) ) 

i know simple stuff input appreciated.

the comma operator

evaluates each of operands (from left right) , returns value of last operand

combined fact == has higher precedence , happens here elecshow ==2 evaluated, 3, 4, ... , 16.

the last evaluation returned and, 16 being truthy value, execution enter else if.

the result differs from

else if ( ( elecshow ==2 ) || ( elecshow ==3 ) || ( elecshow ==4 ) || ( elecshow ==5 ) || ( elecshow ==6 ) || ( elecshow ==8 ) || ( elecshow ==9 ) || ( elecshow ==10 ) || ( elecshow ==16 ) ) 

simply because it's entirely different operator!


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -