I came accross with a question #83 in https://github.com/lydiahallie/javascript-questions
function Car() {
this.make = 'Lamborghini';
return { make: 'Maserati' };
}
const myCar = new Car();
console.log(myCar.make);
To my understanding the code should log 'Lamborghini'and conso;e.log(myCar().make) should log 'Maserati'
But I'm totally wrong, myCar is not a function. Why?
If you intend to use your function as a constructor you don't need to return anything from it. When you invoke your function with new keyword Javascript will create a new object under the hood, bind it to this and return it by default