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