Movatterモバイル変換


[0]ホーム

URL:


  1. 개발자를 위한 웹 기술
  2. JavaScript
  3. JavaScript 참고서
  4. JavaScript error reference
  5. TypeError: "x" is (not) "y"

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

TypeError: "x" is (not) "y"

Message

    TypeError: "x" is (not) "y"    Examples:    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

Error type

TypeError.

What went wrong?

그것은 정확하지 않은 형태이다. 그것은 가끔undefinednull 값을 발생한다.

또한,Object.create() 또는Symbol.keyFor()와 같은 메서드는 반드시 제공되어야하는 특별한 형태를 요구한다.

Examples

Invalid cases

js
// undefined and null cases on which the substring method won't workvar foo = undefined;foo.substring(1); // TypeError: foo is undefinedvar foo = null;foo.substring(1); // TypeError: foo is null// Certain methods might require a specific typevar foo = {};Symbol.keyFor(foo); // TypeError: foo is not a symbolvar foo = "bar";Object.create(foo); // TypeError: "foo" is not an object or null

Fixing the issue

undefined 나 null 값을 가진 null 포인터를 고치기 위해서 아래 예제와 같이typeof 연산자를 사용할 수 있다.

js
if (typeof foo !== "undefined") {  // Now we know that foo is defined, we are good to go.}

같이 보기

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp