1.typeof以字符串的形式返回类型,具体有6种类型:number,boolean,string,function,object,undefined
typeof(1): number typeof(NaN): number typeof(Number.MIN_VALUE): number typeof(Infinity): number typeof("123"): string typeof(true): boolean typeof(window): object typeof(Array()): object typeof(function(){}): function typeof(document): object typeof(null): object typeof(eval): function typeof(Date): function typeof(sss): undefined typeof(undefined): undefined
2.instanceof用来判断对象是否是某个类的实例,返回值为true或者false
var a = new Array();
alert(a instanceof Object);//true;
alert(window instanceof Object);//高版本的浏览器返回true,以前的返回false
时间: 2024-08-04 18:41:27