Why does instanceof return false for some literals?

前端 未结 10 1118
耶瑟儿~
耶瑟儿~ 2020-11-22 13:13
"foo" instanceof String //=> false
"foo" instanceof Object //=> false

true instanceof Boolean //=> false
true instanceof Object //=>         


        
10条回答
  •  礼貌的吻别
    2020-11-22 13:29

    I believe I have come up with a viable solution:

    Object.getPrototypeOf('test') === String.prototype    //true
    Object.getPrototypeOf(1) === String.prototype         //false
    

提交回复
热议问题