摘要
- undefined 是 原始数据类型,值为 undefined ,转布尔值为 false;
- not define 出现在报错信息中;
- null 是 原始数据类型 ,表示"非对象",转布尔值为 false;
- null是一个表示"无"的对象,转为数值时为0;undefined是一个表示"无"的原始值,转为数值时为NaN。
console.log(Number(null)); //0
console.log(Number(undefined)); //NaN
console.log(typeof null); //object
console.log(typeof undefined); //undefined
1、not defined
- 未声明变量且未赋值
//var a;
console.log(a); //未声明变量且未赋值,a is not defined
2、undefined
(1)变量被声明了,但没有赋值时,就等于undefined。
(2) 调用函数时,应该提供的参数没有提供,该参数等于undefined。
(3)对象没有赋值的属性,该属性的值为undefined。
(4)函数没有返回值时,默认返回undefined
3、null
- null 和 undefined 都表示 “无”,
console.log(null == undefined); //true
console.log(null === undefined); //false