JavaScript TypeError – “X” is not a non-null object

This JavaScript exception is not a non-null object that occurs if an object is not passed where it is expected. So the null is passed which is not an object and it will not work.

Message:

TypeError: Invalid descriptor for property {x} (Edge)
TypeError: "x" is not a non-null object (Firefox)
TypeError: Property description must be an object: "x" (Chrome)
TypeError: Invalid value used in weak set (Chrome)

Error Type:

TypeError

Cause of Error: Somewhere in the code an object is expected and is not passed. Automatically null is passed which is not an object and it will not work. User needs to provide a proper object in the given context.

Example 1: In this example, 1 is passed in the given method which is a non-null object, So the error has occurred.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Type Error</title>
</head>
<body>
    <script>
      // 1 is non-null object
      Object.defineProperty({}, 'prop_name', 1); 
    </script>
</body>
</html>

chevron_right


Output(In Chrome console):

TypeError: Property description must be an object: 1

Example 2: In this example, the WeakSet object store object keys, Other types of keys are not accepted. So the error has occurred.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Type Error</title>
</head>
<body>
    <script>
        var var1 = new WeakSet(); 
        var1.add('GFG');
    </script>
</body>
</html>

chevron_right


Output(In Chrome console):

TypeError: Invalid value used in weak set

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.