Null 和 Undefined
Null(空值)
1、Null(空值)类型的值只有一个,就是null
2、null这个值专门用来表示一个为空的对象
3、使用typeof检查一个null值时,会返回object
Undefined(未定义)
1、Undefined(未定义)类型的值只有一个,就是 undefined
2、当声明一个变量,但是并不给变量赋值时,它的值就是 undefined
3、使用 typeof 检查一个 undefined 时,也会返回 undefined
示例:
var a = null;
var b;
console.log(a); ---返回 null
console.log(b); ---返回 undefined
console.log(typeof a); ---返回 object
console.log(typeof b); ---返回 undefined

本文详细介绍了JavaScript中的Null和Undefined类型。Null仅有一个值null,常用于表示空对象引用,而Undefined则在变量声明但未赋值时出现。在使用typeof检查时,null会返回'object',而undefined返回'undefined'。了解这两种基本类型的差异对于JavaScript编程至关重要。
697

被折叠的 条评论
为什么被折叠?



