JavaScript TypeError – Can’t access property “X” of “Y”

This JavaScript exception can’t access property occurs if property access was performed on undefined or null values.
Message:
TypeError: Unable to get property {x} of undefined or
null reference (Edge)
TypeError: can't access property {x} of {y} (Firefox)
TypeError: {y} is undefined, can't access property {x}
of it (Firefox)
TypeError: {y} is null, can't access property {x} of it
(Firefox)
Examples:
TypeError: x is undefined, can't access property "prop"
of it
TypeError: x is null, can't access property "prop" of it
TypeError: can't access property "prop" of undefined
TypeError: can't access property "prop" of null
Error Type:
TypeError
Cause of Error: The property access was performed on any of the undefined or null values in the code.
Example 1: In this example, the GFG is undefined, So the error has occurred.
HTML
let GFG = undefined;GFG.substring(3); // error here |
Output(in console):
TypeError: Unable to get property 'substring' of undefined or null reference
Example 2: In this example, the GFG is null, So the error has occurred.
Javascript
let GFG = null;GFG.substring(3); // error here |
Output(in console):
TypeError: Unable to get property 'substring' of undefined or null reference
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



