Why does instanceof return false for some literals?

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

    This is defined in the ECMAScript specification Section 7.3.19 Step 3: If Type(O) is not Object, return false.

    In other word, if the Obj in Obj instanceof Callable is not an object, the instanceof will short-circuit to false directly.

提交回复
热议问题