Skip to main content
JavaScript Interview Questions Concept Queue P0 Medium

A callback works until you pass it

cart.checkout() works, but passing cart.checkout to a button’s click listener makes it read the wrong cart ID. Explain why the two invocations behave differently. Propose a fix that also lets you remove the listener later.

Official Reference

Model Answer & Explanation

The direct call uses cart as its receiver. Passing cart.checkout passes only the function, not that receiver. A DOM event listener does not call it as cart.checkout(). Register a named wrapper that calls cart.checkout(), or bind the function once and store the result. To remove it, pass the same listener reference and capture setting.

What a Strong Answer Covers

  • Identify which call controls this.
  • Preserve the receiver and keep the same function reference for removal.
Follow-up Interview Question · Why won’t calling bind again inside removeEventListener remove the original listener?

Module Context & References

JavaScript · Applied concepts Debug real scenarios and explain the rule behind each fix.
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.