What does it mean to 'lose this', and how do you fix it?
Quick answer
Passing a method as a bare callback drops the implicit binding so `this` becomes undefined/global. Fix with .bind or an arrow wrapper.
In detail
When you pass `obj.method` to setTimeout or an event listener, the function is called without the dot, so the implicit binding is lost. Fix it with `obj.method.bind(obj)`, an arrow wrapper `() => obj.method()`, or class field arrow methods.
1class Btn {
2 label = "Save";
3 handle() { console.log(this.label); }
4}
5const b = new Btn();
6setTimeout(b.handle); // undefined — lost this
7setTimeout(b.handle.bind(b)); // "Save"
8setTimeout(() => b.handle()); // "Save"Why interviewers ask this: A real-world bug interviewers want you to recognise.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299