JavaScript·Intermediate·Coding·1 min read
How do target and currentTarget differ?
Short interview answer
target is the node where the event originated, subject to retargeting across boundaries. currentTarget is the node whose listener is currently executing. In a delegated handler, currentTarget is the container while target may be a nested icon.
Example
list.addEventListener('click', (e) => { e.currentTarget; // always `list` (where the listener lives) e.target; // the actual clicked node, e.g. an <svg> inside a button});Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.