5种基本数据类型:Undefined、Null、Boolean、Number和String。1复杂数据类型:对象使用typeof来检测typeof运算符返回一个字符串,表示未计算的操作数的类型。typeof的可能返回值:"undefined"——如果值为undefined;"boolean"-如果值为布尔值;"string"-如果值是一个字符串;"number"-如果值为value;"object"-如果此值为对象或为null;"function"-如果这个值是一个函数。注意:typeofnull返回对象。typeof是运算符而不是函数,括号虽然允许,但不是必需的。//typeofstr或typeof(str)可以使用instanceof检测来检测引用类型:知道一个值是什么类型的对象。返回真/假。引用类型的所有值都是Object的实例。如果您使用instanceof运算符检查原始类型的值,该运算符将始终返回false,因为原始类型不是对象。但是instanceof运算符在使用new关键字构造基础数据的包装对象的实例时也会返回true。(instanceof只适用于复杂对象和构造函数创建返回的实例。)当使用instanceof检测undefined和null是否为Object实例时,返回false。functionPerson(){}functionStudent(){}Student.prototype=newPerson();varJohn=newStudent();console.log(JohninstanceofStudent);//trueconsole.log(JohninstancdofPerson);//trueconsole.log(JohninstancdofObject);//真实的变量a;使用instanceof检测undefined和null是否为Object实例时,返回false。一个的类型;//“未定义”一个对象实例;//假varb=null;b的类型;//“对象”binstanceofObject;//false使用构造函数检测
