Why does “,,,” == Array(4) in Javascript?

后端 未结 6 2169
暖寄归人
暖寄归人 2020-12-12 23:14

Boot up your interpreter/console and try the comparison

> \",,,\" == Array(4)
True

Why? At first I thought maybe since you could think

6条回答
  •  心在旅途
    2020-12-13 00:01

    I first thought it was something with the "prototype"... but after a little investigation I reached a sad conclusion...

    Apparently it is an internal and more obscure js thing with not much logic...

    Just try

    Array(4)==Array(4)
    

    and no coercion on types also...

    Array(4)===Array(4)
    

    and you'll get FALSE

    you know that null==null, null===null and even undefined==undefined and undefined===undefined returns TRUE... so... it's a bit obscure...

    Array(4)==[,,,] should be true also

提交回复
热议问题