ECMAScript中有5种简单数据类型:Undefined、Null、Boolean、 Number、和String。还有一个复杂数据类型--Object。
ECMAScript不支持任何创建自定义类型的机制,所以值都成为以上6中数据类型之一。
一.typeof操作符
  typeof操作符是用来检测变量 数据类型,对于值或者变量所以typeof
  操作符会返回如下字符串:

         var box;
	 alert(typeof box);  //box是Undefined类型,值是undefined,类型返回的字符串是undefined
        var box=true;
	 alert(typeof box);  //box是Boolean类型,值是true,类型返回的字符串是boolean
	 var box=100;
	 alert(typeof box);  //box是Number类型,值是100,类型返回的字符串是number
	 var box=‘秦肯‘;
	 alert(typeof box);  //box是String类型,值是秦肯,类型返回的字符串是String
	 var box=null;
	 alert(typeof box);  //box是Null类型,值是null,类型返回的字符串是Object
         var box={};
	 alert(typeof box);  //box是Object类型,值是[object Object],类型返回的字符串是Object
      
	  var box=new Object; 
	 alert(box);  //box是Object类型,值是[object Object],类型返回的字符串是Object
      
	  function box(){
	  }
	 alert(typeof box);  //box是Function类型,值是function box(){},类型返回的字符串是function
typeof 操作符可以操作变量,也可以操作字面量。虽然也可以这样使用:typeof(box),但是 typeof是操作符而非内置函数。
  ps:函数在ECMAScript中是对象,不是一种数据类型。所以,使用typeof来区分function和object是非常有必有的。
原文:http://www.cnblogs.com/linkhtml/p/5790916.html