Skip to content
Related Articles

Related Articles

JavaScript TypeError – “X” is not a non-null object
  • Last Updated : 24 Jul, 2020

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




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

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




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

Output(In Chrome console):

TypeError: Invalid value used in weak set
My Personal Notes arrow_drop_up
Recommended Articles
Page :