typeof 操作符用来检测给定的变量的数据类型,
对一个值使用typeof操作符可能返回下列某个字符串:
"undefined" : 如果这个值没有定义;
"boolean" : 如果这个值是布尔值;
"string" : 如果这个值是字符串;
"number" : 如果这个值是数值;
"object" : 如果这个值是对象或null;
"function" : 如果这个值是函数;
<html>
<head>
</head>
<body>
<script type="text/javascript">
var undef;
var str = 'abc';
var bool = true;
var num = 1;
var func = function () {};
var obj = new Object();
alert(typeof undef); //undefinde
alert(typeof str); //string
alert(typeof bool); //boolean
alert(typeof num); //number
alert(typeof func); //function
alert(typeof obj); //object
alert(typeof null); //object
</script>
</body>
</html>
从技术角度讲,函数在js中也是对象,不是一种数据类型。但函数确实有一些特殊的属性,因此通过
typeof操作符来区分函数和其它对象也是有必要的。