Get to know MDN better
The JavaScript exception "x is (not) y" occurs when there was an unexpected type. Oftentimes, unexpected undefined or null values.
There was an unexpected type. This occurs oftentimes with undefined or null values.
Also, certain methods, such as Object.create() or Symbol.keyFor(), require a specific type, that must be provided.
You cannot invoke a method on an undefined or null variable.
Certain methods might require a specific type.
To fix null pointer to undefined or null values, you can test if the value is undefined or null first.
Or, if you are confident that foo will not be another falsy value like "" or 0, or if filtering those cases out is not an issue, you can simply test for its truthiness.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.