JS Tip of the Day: Constructors Don’t Need Parens

Constructors Don’t Need Parens
Level: Beginner

When you use new to create a new instance with a constructor, if you’re not passing any arguments into that constructor, then you can omit the parenthesis during the call.

let anObject = new Object(); // pretty normal
let equallyAnObject = new Object; // less normal, but also works

While the new operator has a high precedence, it is not greater than that of a property reference. So if you need to access a property immediately from a newly constructed instance, you will need to include the parenthesis. Otherwise it will try to construct the value of the property.

console.log(new Array().length); // 0
console.log(new Array.length); // TypeError: Array.length is not a constructor

More info: