类型错误:"x" 没有属性

当你尝试访问 nullundefined 的属性时,会发生 JavaScript 异常 "null(或未定义)没有属性"。他们没有。

¥The JavaScript exception "null (or undefined) has no properties" occurs when you attempt to access properties of null and undefined. They don't have any.

信息

¥Message

TypeError: Cannot read properties of undefined (reading 'x') (V8-based)
TypeError: null has no properties (Firefox)
TypeError: undefined has no properties (Firefox)
TypeError: undefined is not an object (evaluating 'undefined.x') (Safari)

错误类型

¥Error type

TypeError

什么地方出了错?

¥What went wrong?

nullundefined 都没有你可以访问的属性。

¥Both null and undefined, have no properties you could access.

示例

¥Examples

null 和 undefined 没有属性

¥null and undefined have no properties

js
null.foo;
// TypeError: null has no properties

undefined.bar;
// TypeError: undefined has no properties

也可以看看

¥See also