Javascript中的null和 undefined
Posted eret9616
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript中的null和 undefined相关的知识,希望对你有一定的参考价值。
Javascript Undefined vs NULL
Many a times we often get confused on whats the difference between UNDEFINED and NULL.
undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value.
undefined指一个变量被声明但是没有赋值, null是一个用来赋值的变量,可以分配到一个变量, 意味这个变量没有值
Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
undined和null是完全不同的类型, undefined是一个类型(undefined 类型) , null是一个对象
Unassigned variables are initialized by javascript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.
JavaScript的未初始化的变量默认值是undefined, 一般null都是人手工分配的(不过Object原型对象 的__proto__好像也是null)
undefined是一个value
null 是一个对象
以上是关于Javascript中的null和 undefined的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript中的Undefined / Null 类型相关说明
前端面试准备2----Javascript中的Undefined和null小结