Why does new Number(2) != new String(“2”) in JavaScript

前端 未结 3 1894
名媛妹妹
名媛妹妹 2021-01-18 11:06

The following evaluate to true:

new Number(2) == 2
new String(\"2\") == \"2\"

Obviously, but so do the following:



        
3条回答
  •  情书的邮戳
    2021-01-18 11:47

    Just try:

    new Number(2) == new Number(2)
    

    that returns

    false

    and you will have the answer: there are 2 different objects that have 2 different references.

提交回复
热议问题