What happens if you forget new with a function constructor in JavaScript?
this becomes the global object (or undefined in strict mode). Properties get added to window instead of a new object. The function returns undefined. This is a common bug with function constructors.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in this in Constructors and the new Keyword in JavaScript
It creates a new empty object, sets this to that object inside the function, runs the function body, and returns this (the new object) unless the function returns its own object.
this becomes the global object (or undefined in strict mode). Properties get added to window instead of a new object. The function returns undefined. This is a common bug with function constructors.
Yes. Calling a class constructor without new throws TypeError: Class constructor X cannot be invoked without 'new'. This prevents the forgotten-new bug that function constructors have.
Still have questions?
Browse all our FAQs or reach out to our support team
