primitive Type (value type): Undefined, Null, number, String, Boolean;
Object Type (reference type): Object;
typeof
The standard type can be recognized, null outside (return object), and no specific object type (function excepted) is recognized.
Examples of usage:
var num = 100;typeof num;
Note: Except for number, String, Boolean, undefined, and function types, the remaining types are judged to be object (including null).
instanceof
You can identify built-in object types, custom object types, and cannot discriminate between primitive types.
var arr = [];arr instanceof Array; -->true
Object.prototype.toString.call ()
You can identify the standard type, built-in object type, and not the custom object type.
Object.prototype.toString.call (123); --[Object number]
Constructor
The built-in object types, custom object types, and standard types can be distinguished (but underfined/null not recognized).
var num = 100;num.constructor = = = number; --true;
Return constructor Syntax:
function Getconstructorname (obj) { return (obj===undefined| | obj===null)? obj: (obj.constructor&&obj.constructor.tostring (). Match (/function\s* ([^ (]*)/) [1]);} Match () Gets the number in the returned function number () {[native code]}.
"Front End Learning Note 01" javascript Source method for judging data types