To create a new empty object in javascript we can write in 2 ways.
1. With object literal syntax:
const obj = {}
2.Or with constructor function syntax:
const obj = new Object()
Today I accidentally typed out const obj = new Object
saw it also worked, where it should've thrown
an error because I'd not invoked the constructor function which is done by a set of parenthesis.
I know that the new
operator with a constructor function does 3 things.
1. creates a new empty object.
2. sets the value of this
to the new object.
3. return the newly created object from the constructor function.
Is the constructor functions invocation is optional?
So what am I missing?