TypeOf Judge 6 kinds of
1 //typeof 6 Kinds2Console.log (typeof1);// Number3Console.log (typeof‘‘);//string4Console.log (typeof true);//Boolean5Console.log (typeof{});//Object6Console.log (typeofFN);//function7Console.log (typeofundefined);//undefined
Method:
1 function Istype (value) {// does not support IE62 var str = Object.prototype.toString.call (value); 3 return Str.slice (8,str.length-1). toLowerCase (); 4 }
This comparison is all
1 vardata =NewDate ();2 functionfn () {3Alert (1)4 }5 6Console.log (Istype (1));// Number7Console.log (Istype ("1"));//string8Console.log (Istype (true));//Boolean9Console.log (Istype (FN));//functionTenConsole.log (Istype (NULL));//NULL OneConsole.log (Istype (undefined));//undefined AConsole.log (Istype ({}));//Object -Console.log (Istype ([]));//Array -Console.log (Istype (/12/));//RegExp theConsole.log (Istype (data));//Date
JavaScript Judging data types