(true + false) > 2 + true; Why does this return false?

后端 未结 3 827
再見小時候
再見小時候 2021-01-06 22:06

Im studying javascript and can\'t figure it out why this line returns false:

(true + false) > 2 + true
3条回答
  •  臣服心动
    2021-01-06 22:36

    The reason is called type coercion; You're using two boolean values in an arithmetic operation which is not feasible unless the interpreter converts them into numbers first.

    true --> 1 false --> 0

    Try it yourself; type +true and you will get 1;

提交回复
热议问题