Skip to content
Related Articles

Related Articles

JavaScript TypeError – Can’t access property “X” of “Y”
  • Last Updated : 29 Jul, 2020

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




<script>
    var GFG = undefined;
    GFG.substring(3); // error here
</script>

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.

HTML




<script>
    var GFG = null;
    GFG.substring(3); // error here
</script>

Output(in console):

TypeError: Unable to get property 'substring' of undefined or null reference
My Personal Notes arrow_drop_up
Recommended Articles
Page :