Explain 'Not a constructor function' error in JavaScript?

The "Not a constructor function" error occurs when we try to use the new keyword with a value that isn't a constructor function. This TypeError is thrown when JavaScript expects a constructor but receives a primitive value, object, or non-constructor function.

What Causes This Error

The error occurs when we attempt to instantiate something that cannot be used as a constructor:

  • Primitive values (numbers, strings, booleans)
  • Regular objects
  • Arrow functions (in strict mode)
  • Built-in methods that aren't constructors

Example: Using Primitive as Constructor






Constructor Error Demo












Common Scenarios and Solutions




Constructor Solutions






How to Fix This Error

Problem Solution Example
Using primitive with new Use constructor function or class new String("text") instead of new "text"
Using object with new Create constructor function function MyObj() {}
Using arrow function Use regular function or class function MyFunc() {}

Prevention Tips







Conclusion

The "Not a constructor function" error occurs when using new with non-constructor values. Always ensure you're using constructor functions, classes, or built-in constructors like Array, Object, or Date with the new keyword.

Updated on: 2026-03-15T23:18:59+05:30

387 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements