Friday, July 30, 2021

Javascript Puzzle No.2

Given the code
let working = {
  foo: function() {
    console.log("working");
  }
};

let notworking = {
  foo() {
    console.log("notworking");
  }
}

new working.foo();
new notworking.foo();
and its output
Uncaught TypeError: notworking.foo is not a constructor
please explain why this particular function cannot be used as a constructor function.

Hint: based on this SO question where the explanation is provided.

No comments: