Generic methods (except NaN)

Object.prototype.toString.call()

Determine the data type method

typeof()

Judge the constructor method

instanceof

The only way to determine NaN

isNaN()

* * * * * * * * * * * * * * * * * * * * * *String* * * * * * * * * * * * * * * * * * * * * * * * * * *let str = 'str';
// typeof
console.log(typeof(str));  // string
// The class attribute of the object
console.log(Object.prototype.toString.call(str)); // [object String]* * * * * * * * * * * * * * * * * * * * * *Object* * * * * * * * * * * * * * * * * * * * * * * * * * *let obj = {'obj':'obj'};
// typeof
console.log(typeof(obj)); // object
// Prototype object judgment
console.log(Object.prototype.isPrototypeOf(obj)); // true
// instanceof
console.log(obj instanceof Object); // true
// The class attribute of the object
console.log(Object.prototype.toString.call(obj)); // [object Object]* * * * * * * * * * * * * * * * * * * * * *BigInt* * * * * * * * * * * * * * * * * * * * * * * * * * *let int = 123456789n;
// typeof
console.log(typeof(int)); // bigint
// The class attribute of the object
console.log(Object.prototype.toString.call(int)); // [object BigInt]* * * * * * * * * * * * * * * * * * * * * *Symbol* * * * * * * * * * * * * * * * * * * * * * * * * * *let sym = Symbol('test');
// typeof
console.log(typeof(sym)); // symbol
// The class attribute of the object
console.log(Object.prototype.toString.call(sym)); // [object Symbol]* * * * * * * * * * * * * * * * * * * * * *Boolean* * * * * * * * * * * * * * * * * * * * * * * * * * *let bo = true;
// typeof
console.log(typeof(bo)); // boolean
// The class attribute of the object
console.log(Object.prototype.toString.call(bo)); // [object Boolean]* * * * * * * * * * * * * * * * * * * * * *Number* * * * * * * * * * * * * * * * * * * * * * * * * * *let num = 123;
// typeof
console.log(typeof(num)); // number
// The class attribute of the object
console.log(Object.prototype.toString.call(num)); // [object Number]* * * * * * * * * * * * * * * * * * * * * *NaN* * * * * * * * * * * * * * * * * * * * * * * * * * *let nan = NaN;
// typeof
console.log(typeof(nan)); // number
// The class attribute of the object
console.log(Object.prototype.toString.call(nan)); // [object Number]
// Direct judgment
console.log(isNaN(nan)); // true* * * * * * * * * * * * * * * * * * * * * *undefined* * * * * * * * * * * * * * * * * * * * * * * * * * *let unde = undefined;
// typeof
console.log(typeof(unde)); // undefined
// The class attribute of the object
console.log(Object.prototype.toString.call(unde)); // [object Undefined]* * * * * * * * * * * * * * * * * * * * * *null* * * * * * * * * * * * * * * * * * * * * * * * * * *let nul = null;
// typeof
console.log(typeof(nul)); // object
// The class attribute of the object
console.log(Object.prototype.toString.call(nul)); // [object Null]* * * * * * * * * * * * * * * * * * * * * *Function* * * * * * * * * * * * * * * * * * * * * * * * * * *let fun = function (){};
// typeof
console.log(typeof(fun)); // function
// Prototype object judgment
console.log(Function.prototype.isPrototypeOf(fun)); // true
// instanceof
console.log(fun instanceof Function); // true
// The class attribute of the object
console.log(Object.prototype.toString.call(fun)); // [object Function]* * * * * * * * * * * * * * * * * * * * * *Array* * * * * * * * * * * * * * * * * * * * * * * * * * *let arr = [1.2.3];
// typeof
console.log(typeof(arr));
// Prototype object judgment
console.log(Array.prototype.isPrototypeOf(arr));
// instanceof
console.log(arr instanceof Array);
// The class attribute of the object
console.log(Object.prototype.toString.call(arr));
// Direct judgment
console.log(Array.isArray(arr)); * * * * * * * * * * * * * * * * * * * * * *Set* * * * * * * * * * * * * * * * * * * * * * * * * * *let set = new Set(a);// typeof
console.log(typeof(set));
// Prototype object judgment
console.log(Set.prototype.isPrototypeOf(set));
// instanceof
console.log(set instanceof Set);
// The class attribute of the object
console.log(Object.prototype.toString.call(set)); * * * * * * * * * * * * * * * * * * * * * *Map* * * * * * * * * * * * * * * * * * * * * * * * * * *let map = new Map(a);// typeof
console.log(typeof(map));
// Prototype object judgment
console.log(Map.prototype.isPrototypeOf(map));
// instanceof
console.log(map instanceof Map);
// The class attribute of the object
console.log(Object.prototype.toString.call(map));

Copy the code