如题所述
null和undefined都是Javascript中的基本数据类型,但在使用上比较大的区别。
在类型上的区别
typeof(null); //返回Objecttypeof(undefined); //返回undefined
在使用上的区别
null代表数据项有定义,但是没有赋值,此时初始值为null(空)
undefined代表数据项没有定义,也就没有初始值,因此也就是undefined(未定义)
document.documentElement.onclick //返回nulldocument.documentElement.onSmile //返回undefined
温馨提示:答案为网友推荐,仅供参考