TypeError: null/undefined has no properties
JavaScript の例外 "null (or undefined) has no properties" は、 null および undefined のプロパティにアクセスしようとしたときに発生します。これらはプロパティを何も持ちません。
エラーメッセージ
TypeError: Cannot read properties of undefined (reading 'x') (V8-based) TypeError: Cannot destructure 'x' as it is undefined. (V8-based) TypeError: Cannot destructure property 'x' of 'y' as it is undefined. (V8-based) TypeError: null has no properties (Firefox) TypeError: undefined has no properties (Firefox) TypeError: undefined is not an object (evaluating 'undefined.x') (Safari) TypeError: Right side of assignment cannot be destructured (Safari)
エラー型
エラーの原因
null と undefined に、アクセス可能なプロパティはありません。したがって、これらに対してプロパティアクセサーを使用したり、構造分解を行ったりすることはできません。
例
>null と undefined にはプロパティがない
js
null.foo;
// TypeError: null has no properties
undefined.bar;
// TypeError: undefined has no properties