Skip to content
Related Articles

Related Articles

JavaScript TypeError – “X” is not a constructor
  • Last Updated : 24 Jul, 2020

This JavaScript exception is not a constructor that occurs if code tries to use an object or a variable as a constructor, which is not a constructor.

Message:

TypeError: Object doesn't support this action (Edge)
TypeError: "x" is not a constructor

TypeError: Math is not a constructor
TypeError: JSON is not a constructor
TypeError: Symbol is not a constructor
TypeError: Reflect is not a constructor
TypeError: Intl is not a constructor
TypeError: Atomics is not a constructor

Error Type:

TypeError

Cause of Error: Somewhere the code is trying to use an object or a variable as a constructor, which is not a constructor.

Example 1: In this example, the variable(‘var2’) which is a string, is used as a constructor, So the error has occurred.



HTML




<!DOCTYPE html>
<html>
<head>
    <title>Type Error</title>
</head>
<body>
    <script>
    var var2 = "This is string";
    document.write(new var2());
    </script>
</body>
</html>

Output(In Edge console):

TypeError: Object doesn't support this action

Example 2: In this example, Math is used as a constructor, So the error has occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Type Error</title>
</head>
<body>
    <script>
    document.write(new Math());
    </script>
</body>
</html>

Output(In Edge console):

TypeError: Object doesn't support this action
My Personal Notes arrow_drop_up
Recommended Articles
Page :