JavaScript · this · Fresh / Intern · Concept
How is the value of `this` determined in JavaScript?
Short Interview Answer
`this` is set by the call site (how the function is invoked), not where it was defined — except arrows, which inherit `this` lexically.
Detailed Explanation
Rules of thumb: default binding — plain `fn()` uses `undefined` in strict mode / global object in sloppy mode; implicit binding — `obj.fn()` sets `this` to `obj`; explicit binding — `call`/`apply`/`bind` set `this`; `new` binding — `new Fn()` sets `this` to the created instance. Arrow functions do not have their own `this`; they close over the surrounding `this`. Losing a method reference (`const f = obj.fn; f()`) drops implicit binding. Understanding call-site rules is essential for debugging.
Interview Tip
List the four bindings plus arrows — a clear structured answer.
Common Mistake
Saying `this` always refers to the 'owner' object where the function was written.