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
What does this print?
const obj = {
x: 41,
getX() { return this.x; }
};
const fn = obj.getX;
console.log(fn(), obj.getX.call({ x: 99 }));
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?
:: Copyright KIRUPA 2024 //--