typeof
JS数据类型有7中:
- 基本数据类型: String,Number,Boolean, Null, Undefined,Symbol
- 引用数据类型: Object({},[], function)
typeof返回值有7种,且值都是字符串类型
分别是:undefined,string,number,boolean,object,function,Symbol
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"