Why a class without parentheses can also create an instance?

Why a class without parentheses can also create an instance?
0.0 0

#1

Hi, I’ve found this strange syntax in an exercise. Why a class without parentheses can also create an instance? Can we just save the parentheses all the time?

class Person {
    constructor () {
        this.message = "You've created a new human being!";
    }
}

var john = new Person();
john.message; //->"You've created a new human being!"

var tina = new Person;
tina.message; //->-->"You've created a new human being!"

#2

I’m curious as well.
Haven’t started playing with classes yet.
I suspect that using parans is better just for the sake of keeping things consistent.

Also if you want to pass any parameters to use in the constructor you can do that with the parans.
Ie:
let bob = new Person(“bob”) - and then utilize the passed parameters in the constructor


#3

It’s not specific to classes, it is a “feature” of the language: if a function is called using the new operator, and the function has no arguments, the parentheses can be omitted. It’s imo a pointless, as it’s just confusing, and can directly cause program errors if you directly chain methods (new Date.getMonth() vs new Date().getMonth())