第六章 类型 相等 转换等 一、类型 1 typeof();
typeof是一个内置的JavaScript运算符,可用于探测其操作数的类型。
例:
1 <script language="JavaScript" type="text/JavaScript"> 2 3 var test1="abcdef"; //string 4 5 var test2=123; //number 6 7 var test3=true; //boolean 8 9 var test4={}; //object 10 11 var test5=[]; //object 12 13 var test6; //undefined 14 15 var test7={"asdf":123}; //object 16 17 var test8=["asdf",123]; //object 18 19 function test9(){return "asdfg"}; //function 20 21 22 23 console.log(typeof test1);//string 24 25 console.log(typeof test2);//number 26 27 console.log(typeof test3);//boolean 28 29 console.log(typeof test4);//object 30 31 console.log(typeof test5);//object 32 33 console.log(typeof test6);//undefined 34 35 console.log(typeof test7);//object 36 37 console.log(typeof test8);//object 38 39 console.log(typeof test9);//function 40 41 </script>