1. Simple judgment, TypeOf and constructor
(1) typeof
typeof (1); Numbertypeof ("s"); Stringtypeof (a); Undefinedtypeof (TRUE); Booleantypeof (a); Functiontypeof (a); Object (objects, NULL, array)
(2) constructor
Console.log ([].constructor = = Array); Console.log ({}.constructor = = Object); Console.log ("string". Constructor = = String); Console.log ((123). constructor = = number); Console.log (true.constructor = = Boolean);
2, the judgment of the array
(1) rigorous type judgment
function IsArray (object) { return object && typeof object=== ' object ' && Array = = Object.constructor;}
(2) Characteristic judgment
function IsArray (object) { return object && typeof object=== ' object ' && typeof object.length=== ' number ' && typeof object.splice=== ' function ' && //Determine if the length property is enumerable for arrays Will get false ! ( Object.propertyisenumerable (' length '));}
(3) The simplest method of judging
function IsArray (o) { return Object.prototype.toString.call (o) = = = ' [Object Array] ';}
JS Judging type