Determination of the type commonly used in four ways

  1.typeof

    Can correctly determine the primitive types other than null (object type determines a bit touching a)

    Null judgment to be wrong:

  2.instanceof

    a instanceof b

    It can more accurately determine the type of object, but can not determine the original type

    Principle: Find the b in a prototype chain of whether

    

  3.constructor (by determining if an instance of a constructor)

 

  4.toString (recommended Object.prototype.toString.call (), because toString method may be overridden, can not achieve the best results)

    

 

Guess you like

Origin www.cnblogs.com/angle-xiu/p/11300697.html