Code Fix

初級 › undefinedのプロパティ読み取りエラーの原因 › パターン4

undefinedのプロパティ読み取りエラーの原因

undefinedになった値のプロパティやメソッドにアクセスしようとしたときに出る、JavaScript学習者が最も多く遭遇するエラーです。

 1  let profile;
 2  function loadProfile() {
 3    ____________________________
                    ^
 4  }
 5  profile = loadProfile();
 6  console.log(profile.email);
main.js:6 console.log(profile.email); ^ TypeError: Cannot read properties of undefined (reading 'email')

空欄を埋めて実行を通す

広告
広告スロット(未設定)

undefinedのプロパティ読み取りエラーの原因

値が本当にundefinedになる典型的な場面を整理します。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)