Interview practice question
this is undefined inside a callback
Frontend Engineering · JavaScript Core · Beginner
Inside a class method, a callback passed to setTimeout throws because this is undefined. How do you fix it?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Callback called as plain function → this lost.
- Use arrow function.
- Or bind(this).
- Class field arrow methods.
- Understand call-site rule.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.