I think the questions might need some clarification as well.
-
Yes, I’d say you are responsible for returning the object in that case.
-
Yes and no. A constructor function can be called without
newbut then it doesn’t work the same way. There are for example built-in JS constructor functions you can call with or withoutnew. They do not return the same thing.
typeof new Date()
'object'
typeof Date()
'string'
- A class is considered syntactic sugar. But I’m not sure what it is you are comparing it against exactly. For one, you can’t call it without
newso as per #2 they are not the same. Hoisting also doesn’t work the same.
const person = new Person('John'); // Cannot access 'Person' before initialization
class Person {
constructor(name) {
this.name = name;
}
sayHello() {
return `Hello, I'm ${this.name}`;
}
}
const person = Person('John'); // Class constructor Person cannot be invoked without 'new'
Anyway, I would agree that the questions do call for research in any case.