Is null considered zero and undefined not a number on arithmetic expressions?

后端 未结 3 1570
离开以前
离开以前 2020-12-17 10:45

Is null evaluated to 0 and undefined to NaN on arithmetic expressions?

According to some testing it seems so:

3条回答
  •  被撕碎了的回忆
    2020-12-17 11:16

    Without being type bound,

    null == false == 0
    
    null !== false !== 0
    

    http://www.mapbender.org/JavaScript_pitfalls:_null,_false,_undefined,_NaN#0_6

    With that said, null == 0, null + 4 = 4

    I hope this helps.

提交回复
热议问题