Javascript comparisons -


i know why following comparisons in javascript give me different results.

(1==true==1) true  (2==true==2) false  (0==false==0) false  (0==false) true 

i can not figure out why.

the tests equivalent these:

(true==1) true  (false==2) false  (true==0) false 

which equivalent these:

(1==1) true  (0==2) false  (1==0) false 

in each case == converts boolean number 1 or 0. first == in each 1 gives initial true/false value, used first operand second ==.


or put inline:

((1==true)==1) ((1==1)   ==1) ((true)   ==1) ((1)      ==1) true  ((2==true)==2) ((2==1)   ==2) ((false)  ==2) ((0)      ==2) false  ((0==false)==0) ((0==0)    ==0) ((false)   ==0) ((0)       ==0) false 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -