javascript 数据类型

JavaScript 六种数据类型
number 如 123;
string  如 'string';
boolean 如 true;
object 如 function  array;
null 如 null;
undefined 如 undefined;

数据类型检测
1.typeof



2.instanceof

基于原型链操作。obj instanceof Object。
左操作数为对象,不是就返回false,右操作数必须是函数对象或者函数构造器,不是就返回typeError异常。


instanceof坑:不同window或iframe之间的对象类型检测不能使用instanceof!
3.Object.prototype.toString


4.constructor
任何对象都有constructor属性,继承自原型的,constructor会指向构造这个对象的构造器或者构造函数。
constructor可以被改写,所以使用要小心。





猜你喜欢

转载自xiaotongeye.iteye.com/blog/2411425