typeof 用于区分原始类型 和 对象类型。
instanceof 用户与区分不同的对象类型。
var s = “Nicholas”;
var b = true;
var i = 22;
var u;
var n = null;
var o = new Object();
alert(typeof s); //string
alert(typeof i); //number
alert(typeof b); //boolean
alert(typeof u); //undefined
alert(typeof n); //object
alert(typeof o); //object
instanceof 用户与区分不同的对象类型。
var Person = function(){}
var person = new Person();
alert(person instanceof Person); //true is the variable person an Person ?
alert(person instanceof Object); //true is the variable person an Object?
alert(colors instanceof Array); //is the variable colors an Array?
alert(pattern instanceof RegExp); //is the variable pattern a RegExp?