JavaScript ReferenceError – Reference to undefined property “x”

This JavaScript warning reference to undefined property occurs if a script tries to access an object property that doesn’t exist.

Message:

ReferenceError: reference to undefined property "x" (Firefox)

Error Type:

ReferenceError(Only reported by firefox browser)

Cause of the error: The script is trying to access an object property that doesn’t exist. 

Example 1: In this example, the valid property is accessed, So the error has not occurred. 



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <script src=
        </script>
    </head>
    <body style="text-align: center;">
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
          
<p>
            JavaScript ReferenceError 
            Reference to undefined property
        </p>
  
        <button onclick="Geeks();">
            click here
        </button>
        <p id="GFG_DOWN"></p>
  
        <script>
            var el_down = document.getElementById("GFG_DOWN");
            function GFG() {
                "use strict";
                var AR_GFG = { prop_1: "Val_1" };
                return AR_GFG.prop_1;
            }
            function Geeks() {
                try {
                    GFG();
                    el_down.innerHTML =
                      "'Reference to undefined property'"+
                      " error has not occurred";
                } catch (e) {
                    el_down.innerHTML = 
                      "'Reference to undefined property'"+
                      "error has occurred";
                }
            }
        </script>
    </body>
</html>

chevron_right


Output: 

Example 2: In this example, the undefined property is accessed, So the error has occurred. 

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <script src=
        </script>
    </head>
    <body style="text-align: center;">
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
          
<p>
            JavaScript ReferenceError 
            Reference to undefined property
        </p>
  
        <button onclick="Geeks();">
            click here
        </button>
        <p id="GFG_DOWN"></p>
  
        <script>
            var el_down = document.getElementById("GFG_DOWN");
            function GFG() {
                "use strict";
                var GFG = {};
                return GFG.prop1;
            }
            function Geeks() {
                try {
                    GFG();
                    el_down.innerHTML = 
                      "'Reference to undefined property'"+
                      "error has not occurred";
                } catch (e) {
                    el_down.innerHTML = 
                      "'Reference to undefined property'"+
                      "error has occurred";
                }
            }
        </script>
    </body>
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.