cf.completefrontend

Predict the outputMedium

What does this log when a constructor returns a value?

What does this log?
function Car(make) {
  this.make = make;
  return { make: "Tesla" };
}
 
function Bike(make) {
  this.make = make;
  return "ignored";
}
 
class Box {
  constructor() {
    return [1, 2];
  }
}
 
const car = new Car("Ford");
const bike = new Bike("BMX");
const box = new Box();
 
console.log(car.make, car instanceof Car);
console.log(bike.make, bike instanceof Bike);
console.log(box, box instanceof Box);

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…