undefined的知识

1.undefined如何出现

对于JavaScript,解释器在访问尚未初始化的变量或对象属性时返回undefined;函数没有返回值,是undefined

2.null如何出现

null表示缺少的对象引用,JS本身不会将变量或对象属性设置为null;

一些原生方法,比如String.prototype.match(),可以返回null来表示丢失的对象。

3.常出现的错误:

TypeError: 'undefined' is not a function

TypeError: Cannot read property '<prop-name>' of undefined

type errors

4.undefined

1.)未为变量赋值时默认值为undefined

该标准明确定义,当访问未初始化的变量、不存在的对象属性、不存在的数组元素等时,将接收到一个undefined 的值

2.)Undefined type是其唯一值为undefined 值的类型

typeof undefined返回“undefined”字符串

console.log(typeof undefined) //字符串undefined
console.log(typeof undefined ==="undefined") //true

let nothing;

typeof nothing === "undefined"; // => true

3.)导致undefined的常见场景

(1).

 
知识兔
计算机