What This Refers To

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

The problem

  • medium
  • Pro

A class has a method that reads this dot name. Calling it directly works, but passing the method to a button's click handler or to a timer makes this undefined. Explain how JavaScript decides what this means, and give two ways to fix the bug.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →