Why does instanceof return false for some literals?

前端 未结 10 803
耶瑟儿~
耶瑟儿~ 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:34

    You can use constructor property:

    'foo'.constructor == String // returns true
    true.constructor == Boolean // returns true
    

提交回复
热议问题