Open In App

JavaScript TypeError – “X” has no properties

Last Updated : 22 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This JavaScript exception null (or undefined) has no properties that occur if there is an attempt to access properties of null and undefined. They don’t have any such properties.

Message:

TypeError: Unable to get property {x} of undefined or null reference (Edge)
TypeError: null has no properties (Firefox)
TypeError: undefined has no properties (Firefox)

Error Type:

TypeError

Cause of Error: Somewhere, there is access to properties of null or undefined.

Example 1: In this example, the variable(‘GFG’) is assigned the null value and It doesn’t have any property, So the error has occurred.

Javascript




let GFG = null;
console.log(GFG.prop_name);


Output(In Edge console):

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

Example 2: In this example, the variable(‘var_name’) is assigned the undefined value and It doesn’t have any property, So the error has occurred.

Javascript




let var_name = undefined;
console.log(var_name.prop_name);


Output(In Edge console):

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

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

Similar Reads