Why does this click handler run immediately?

Quick DOM question.

button.addEventListener('click', save());

Why does save run right away, and what is the correct version.

WaffleFries

Because save() calls the function immediately and passes its return value to addEventListener.

Yoshiii

Wrap it in a function or pass the function reference directly, so use button.addEventListener('click', save) or button.addEventListener('click', () => save()) if you need arguments.

Hari