CodePark/ questions / this & binding
START PRACTICINGPRACTICE
Frontend question · JavaScript › this & binding

What does this log?

"use strict";
function show() {
  return this;
}
const obj = { show };
console.log(obj.show() === obj, show(), show.call(42));
true undefined 42

The answer is true undefined 42.
•
obj.show() uses implicit binding, so this is obj.
• A plain call
show() in strict mode gives undefined, not the global object.
• In strict mode,
call(42) passes the primitive 42 as it is.

The tempting option "true undefined [Number: 42]" is wrong because of strict mode. Only sloppy (non-strict) mode would box
42, which means wrap it in a Number object.