JS Quiz: Medium: Method extraction and this binding

What does this print?

const obj = {
  x: 41,
  getX() { return this.x; }
};

const fn = obj.getX;
console.log(fn(), obj.getX.call({ x: 99 }));
  • 41 99
  • undefined 99
  • 99 99
  • TypeError is thrown
0 voters

Ellen

You lost me at “in strict mode it’s undefined” — are we assuming modules/strict here, and if not wouldn’t fn() end up reading from the global object (so potentially window. x) instead of printing undefined?