typeof
typeof
用来检测变量的数据类型,返回一个字符串,是一个运算符并不是函数。在ES5中JavaScript的数据类型有:Undefined、Null、Boolean、Number、String、Object,在ES6中新加了Symbol,但是用typeof 返回的数据类型不是和这些值对应的
console.log(typeof null); //typeof不会返回Null类型,null值的类型返回了object
console.log(typeof undefined);
console.log(typeof NaN);
console.log(typeof document);
console.log(typeof Math.floor);
console.log(typeof true);
var str = new String("test");
console.log(typeof str);
function Test(){}
console.log(typeof (new Test()));
console.log(typeof (new Array()));
console.log(typeof (new Function()));
console.log(typeof document.all)// "undefined"
console.log(typeof myVar);
var myVar = "myVar";
console.log(typeof myLet);//Uncaught ReferenceError: myLet is not defined
let myLet = "myLet";
console.log(typeof myConst);//Uncaught ReferenceError: myConst is not defined
const myConst = "myConst";