Is there any difference between
var obj1 = new Constructor;
and
var obj2 = new Constructor();
given that Constructor
is a constructor function?
When we call a function with parentheses, the function gets execute and returns the result to the callable. In another case, when we call a function without parentheses, a function reference is sent to the callable rather than executing the function itself.
Without parentheses you're not actually calling the function. A function name without the parentheses is a reference to the function. We don't use the parentheses in that code because we don't want the function to be called at the point where that code is encountered.
According to the MDN docs:
[...] "new foo" is equivalent to "new foo()", i.e. if no argument list is specified, "foo" is called without arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With