CARVIEW |
Select Language
HTTP/2 200
content-type: text/html
x-guploader-uploadid: AAwnv3KzwP-9Ha7ib_jspjo6ZPki0Zj7fEX9zWCQTEgy3EZq56IHeuh9GYkxO-jPjWrGixNG
cache-control: public, max-age=3600
expires: Wed, 08 Oct 2025 08:08:14 GMT
last-modified: Wed, 08 Oct 2025 01:13:52 GMT
etag: W/"917bba69db490e057db7ff08f8715204"
x-goog-generation: 1759886032027200
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 199990
x-goog-meta-goog-reserved-file-mtime: 1759884225
x-goog-hash: crc32c=YgfAGw==, md5=kXu6adtJDgV9t/8I+HFSBA==
x-goog-storage-class: STANDARD
accept-ranges: none
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
alt-svc: clear
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
strict-transport-security: max-age=63072000
content-security-policy: default-src 'self'; script-src 'report-sample' 'self' 'wasm-unsafe-eval' https://www.google-analytics.com/analytics.js https://www.googletagmanager.com/gtag/js assets.codepen.io production-assets.codepen.io https://js.stripe.com 'sha256-XNBp89FG76amD8BqrJzyflxOF9PaWPqPqvJfKZPCv7M=' 'sha256-YCNoU9DNiinACbd8n6UPyB/8vj0kXvhkOni9/06SuYw=' 'sha256-PZjP7OR6mBEtnvXIZfCZ5PuOlxoDF1LDZL8aj8c42rw='; script-src-elem 'report-sample' 'self' 'wasm-unsafe-eval' https://www.google-analytics.com/analytics.js https://www.googletagmanager.com/gtag/js assets.codepen.io production-assets.codepen.io https://js.stripe.com 'sha256-XNBp89FG76amD8BqrJzyflxOF9PaWPqPqvJfKZPCv7M=' 'sha256-YCNoU9DNiinACbd8n6UPyB/8vj0kXvhkOni9/06SuYw=' 'sha256-PZjP7OR6mBEtnvXIZfCZ5PuOlxoDF1LDZL8aj8c42rw='; style-src 'report-sample' 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self'; connect-src 'self' developer.allizom.org bcd.developer.allizom.org bcd.developer.mozilla.org updates.developer.allizom.org updates.developer.mozilla.org https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com https://incoming.telemetry.mozilla.org https://observatory-api.mdn.allizom.net https://observatory-api.mdn.mozilla.net https://api.github.com/search/issues stats.g.doubleclick.net https://api.stripe.com; font-src 'self'; frame-src 'self' interactive-examples.mdn.mozilla.net interactive-examples.mdn.allizom.net mdn.github.io live-samples.mdn.mozilla.net live-samples.mdn.allizom.net *.mdnplay.dev *.mdnyalp.dev *.play.test.mdn.allizom.net https://v2.scrimba.com https://scrimba.com jsfiddle.net www.youtube-nocookie.com codepen.io survey.alchemer.com https://js.stripe.com; img-src 'self' data: *.githubusercontent.com *.googleusercontent.com *.gravatar.com mozillausercontent.com firefoxusercontent.com profile.stage.mozaws.net profile.accounts.firefox.com developer.mozilla.org mdn.dev interactive-examples.mdn.mozilla.net interactive-examples.mdn.allizom.net wikipedia.org upload.wikimedia.org https://mdn.github.io/shared-assets/ https://mdn.dev/ https://*.google-analytics.com https://*.googletagmanager.com www.gstatic.com; manifest-src 'self'; media-src 'self' archive.org videos.cdn.mozilla.net https://mdn.github.io/shared-assets/; child-src 'self'; worker-src 'self';
x-frame-options: DENY
origin-trial: AxVILwizhbMjxFeHOn1P3R8niO1RJY/smaK4B4d1rLzc1gTaxtXMSaTi+FoigYgCw40uFRDwFcEAeqDR+vVLOW4AAABfeyJvcmlnaW4iOiJodHRwczovL2RldmVsb3Blci5tb3ppbGxhLm9yZyIsImZlYXR1cmUiOiJQcml2YXRlQXR0cmlidXRpb25WMiIsImV4cGlyeSI6MTc0MjA3OTYwMH0=
x-cloud-trace-context: 27b73382a5a92e85c7837f5bef138db6
date: Wed, 08 Oct 2025 07:08:15 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache: miss
TypeError: "x" is (not) "y" - JavaScript | MDN
Toggle sidebar
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
TypeError: "x" is (not) "y"
JavaScript の例外 "x is (not) y" は、予期しない型があったときに発生します。よくあるのは、予期せず undefined
または null
の値があった場合です。
エラーメッセージ
js
TypeError: Unable to get property {x} of undefined or null reference (Edge)
TypeError: "x" is (not) "y" (Firefox)
例:
TypeError: "x" is undefined
TypeError: "x" is null
TypeError: "undefined" is not an object
TypeError: "x" is not an object or null
TypeError: "x" is not a symbol
エラーの種類
TypeError
エラーの原因
予期しない型がありました。これは undefined
または null
の値でしばしば発生します。
また、Object.create()
や Symbol.keyFor()
のようなある種のメソッドは、特定の型を要求し、それを提供する必要があります。
例
>無効な場合
js
// undefined と null の場合、substring メソッドは動作しません。
var foo = undefined;
foo.substring(1); // TypeError: foo is undefined
var foo = null;
foo.substring(1); // TypeError: foo is null
// ある種のメソッドでは、特定の型が求められることがあります。
var foo = {};
Symbol.keyFor(foo); // TypeError: foo is not a symbol
var foo = "bar";
Object.create(foo); // TypeError: "foo" is not an object or null
問題の修正
null ポインターを undefined
値に修正するには、次のように typeof 演算子を用いて行うことができます。
js
if (foo !== undefined) {
// これで、 foo が定義されていることがわかるので、実行することができます。
}
if (typeof foo !== "undefined") {
// 同じというのは良い考えですが、この実装を使わないでください。 - 本当の
// undefined の値と未宣言の変数が混同されて問題が発生する可能性があります。
}