Javascript !instanceof If Statement

前端 未结 3 1291
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 21:11

This is a really basic question really just to satisfy my curiosity, but is there a way to do something like this:

if(obj !instanceof Array) {
    //The obje         


        
3条回答
  •  [愿得一人]
    2020-12-12 22:06

    Enclose in parentheses and negate on the outside.

    if(!(obj instanceof Array)) {
        //...
    }
    

    In this case, the order of precedence is important (https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Operator_Precedence). The ! operator precedes the instanceof operator.

提交回复
热议问题