Open In App

JavaScript TypeError – “X” is (not) “Y”

Last Updated : 02 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This JavaScript exception X is (not) Y occurs if there is a data type that is not expected there. Unexpected is undefined or null values.

Message:

TypeError: Unable to get property {x} of undefined or null reference (Edge)
TypeError: "x" is (not) "y" (Firefox)

Few example are given below:
TypeError: "x" is undefined
TypeError: "y" is null
TypeError: "undefined" is not an object
TypeError: "y" is not an object or null
TypeError: "x" is not a symbol

Error Type:

TypeError

Cause of Error: There is an unexpected datatype provided to any of the methods, Which expects something else. This occurs with undefined or null values.

Example 1: In this example, the variable(‘var_name’) is undefined, So the error has occurred.

Javascript




let var_name = undefined;
console.log(var_name.substring(3));


Output(In Edge console):

TypeError: Unable to get property 'substring' of undefined or null reference

Example 2: In this example, the variable(‘var1’) is null, So the error has occurred.

Javascript




let var1 = null;
console.log(var1.substring(3));


Output(In Edge console):

TypeError: Unable to get property 'substring' of undefined or null reference

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads