乐趣区

检查数据类型

typeof 在 ES6 之前 typeof 返回值有 6 种,且值都是字符串类型分别是:undefined,string,number,boolean,object,function
var a;
typeof a; // “undefined”

a = “hello world”;
typeof a; // “string”

a=42;
typeof a; // “number”

a = true;
typeof a; // “boolean”

a = null;
typeof a; // “object”(注意)

a = undefined;
typeof a; // “undefined”

a={b:”c”};
typeof a; // “object”

function test(){
return 1;
}
typeof test // “function”

退出移动版