typeof 操作符返回的类型共有七种
- undefined: 表示值未定义
- boolean:表示值为布尔值
- string:表示值为字符串
- number:表示值为数值
- object:表示值为对象
- function:表示值为函数
- symbol:表示值为符号
undefined
let msg;
console.log(typeof msg);
console.log(typeof msg1);
boolean
let msg = false;
console.log(typeof msg);
console.log(typeof true);
string
let msg = 'false';
console.log(typeof msg);
console.log(typeof 'wenqing');
number
let msg = 10;
let random = Math.random();
console.log(typeof msg);
console.log(typeof random);
object
let obj = new Object();
let obj1 = [1, 2, 3, 5];
let nul = null;
let arr = new Array();
console.log(typeof obj);
console.log(typeof obj1);
console.log(typeof nul);
console.log(typeof arr);
function
function fn() {}
console.log(typeof fn);
symbol
let sym = Symbol();
console.log(typeof sym);