// typeof 作用: 检测数据类型,返回: 小写字母字符串, *** 作数: 简单数据类型/函数/对象
console.log(typeof(undefined)); // undefined
console.log(typeof(true)); // boolean
console.log(typeof(false)); // boolean
console.log(typeof(5)); // number
console.log(typeof(4.5555)); // number
console.log(typeof('4')); // string
console.log(typeof("4")); // string
console.log(typeof(function() {})); // function
console.log(typeof(Symbol)); // function
console.log(typeof(Symbol())); // Symbol
console.log(typeof(new Function()));//function
console.log(typeof([])); //object
console.log(typeof({})); //object
console.log(typeof(null)); //object
console.log(typeof(new Array())); //object
console.log(typeof(new Object())); //object
console.log(typeof(new Error())); //object
console.log(typeof(new Number())); //object
console.log(typeof(new String())); //object
console.log(typeof(new Date())); //object
console.log(typeof(new Boolean())); //object
// instanceof 作用: 检测对象之间的关联性, 返回: 布尔值,
*** 作数: 左边的类型值一定是引用类型,右边必须是函数
console.log(new Number(999) instanceof Number); // true
console.log(new String('999') instanceof String); // true
console.log(new Array() instanceof Array); // true
console.log(new Object() instanceof Object); // true
console.log(9999 instanceof Number); // false
console.log('string' instanceof String); // false
console.log(true instanceof Boolean); // false
console.log([] instanceof Array); // true
console.log({} instanceof Object); // true
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)