转载自 http://blog.csdn.net/xujiaxuliang/archive/2009/10/21/4708353.aspx  

null 与 undefined 区别: null 是js的保留字(独一无二的值),可以理解为无对象(因为typeof null =='object'),当null在布尔环境下时,转为false, 当在数字环境时转为0,当在字符串环境时转为‘null’;undefined是js实现的全局变量,是指未声明的变量,或者是使用已经声明但未赋值的变量,或者是使用了一个并不存在的对象属性;当undefined 在布尔环境下时,转为false, 当在数字环境时转为NaN,当在字符串环境时转为‘undefined ’;

 

(1) typeof: 为了从对象中区分出基本类型的。但数组是 Object , 函数是 function , undefined 是undefined , null 是 object。
(2) Object.prototype.toString.call :是指使用最原始的 Object 的原型对象 prototype 的 toString 方法来判断输出的字符串。 因为最原始的 Object 的原型对象 prototype 的 toString 方法返回的字符串总为:[object ** ]  ,(其中 ** 可代表: Array  或 Function 或 Object 等 

isNull:  {  return o === null ;}

isUndefined : {  return typeof o === "undefined"   }

isBoolean: { return typeof o == "boolean" }

isNumber: {return typeof == "number" } //isFinite 来检测数字是否为有限的,即不是 NaN、负无穷或正无穷

isArray: { return ( Object.prototype.toString.call(o) =="[object Array]" ) }

isString: {return typeof o == "string"; }

isFunction: {return typeof o === "function" || ( Object.prototype.toString.call(o) =="[object function]" ) }

isObject:{return o&&( typeof o =="object"||isFunction(o) ) }  //认为Object 与 Function 都是 Object。

 posted on 2015-07-30 09:17  晨祥  阅读(201)  评论(0编辑  收藏  举报