This page was translated from English by the community.Learn more and join the MDN Web Docs community.
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
In this article
Error type
What went wrong?
그것은 정확하지 않은 형태이다. 그것은 가끔undefined 나null 값을 발생한다.
또한,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 nullFixing the issue
undefined 나 null 값을 가진 null 포인터를 고치기 위해서 아래 예제와 같이typeof 연산자를 사용할 수 있다.
js
if (typeof foo !== "undefined") { // Now we know that foo is defined, we are good to go.}