Movatterモバイル変換


[0]ホーム

URL:


  1. 給開發者的 Web 技術文件
  2. JavaScript
  3. JavaScript 參考文件
  4. JavaScript 錯誤參考
  5. TypeError: null/undefined has no properties

此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in EnglishAlways switch to English

TypeError: null/undefined has no properties

當你嘗試存取nullundefined 的屬性時,會發生 JavaScript 的「null (or undefined) has no properties」例外,因為它們沒有任何屬性。

訊息

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)

錯誤類型

TypeError

哪裡出錯了?

nullundefined 都沒有可以存取的屬性。因此,你不能對它們使用屬性存取器,也不能解構它們。

範例

null 和 undefined 沒有屬性

js
null.foo;// TypeError: null has no propertiesundefined.bar;// TypeError: undefined has no properties

參見

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp