Typeof typeof() // Can only detect the basic datatype and created by literalsfunction// Special: detect basic data type NULL,typeof NULL ==='object'; Var a=1; var a=1; console.log(typeof a); //'number'//2) Typeof NULL ==='object'; console.log(typeof null); //'object'; Var num=new Number(1); var num=new Number(1); console.log(typeof num); //2. Instanceof: Checks whether an instance belongs to a class, and returns if it doestrueOtherwise returnfalse// The value of the primitive data type created with literals cannot be detected // as long as the class is returned on the prototype chain of the instancetrue//1) Instanceof can't detect the value of primitive datatypes created with literals'1'; console.log(str instanceof String); //false//2) return as long as the class is on the prototype chain of the instancetrue; var str=new String(); console.log(str instanceof Object); //true
var ary=new Array();
console.log(ary instanceof Array); //true/ / 3. The constructor: the prototype is the object data type, it is also an object data type of attribute value of this object is naturally bring a constructor attribute, attribute values refer to the prototype object class constructor Constructor == class overridden or inherited var num=123; console.log(num.constructor===Number); //true/ / 4. Object. The prototype. ToString. Call (instance) / / all data types can detect < / script >Copy the code