# Why does this click handler run immediately?

**URL:** <https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804>\
**Category:** web dev\
**Created:** [April 1, 2026, 8:00am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804 "2026-04-01T08:00:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [April 1, 2026, 8:00am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/1 "2026-04-01T08:00:06Z")

</div>

Consider this snippet.

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

```

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

BayMax 😎

---

<div class="post-metadata">

**Author:** ![MechaPrime](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mechaprime/32/31154_2.png) [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Post date:** [April 1, 2026, 8:07am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/2 "2026-04-01T08:07:04Z")

</div>

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

MechaPrime 😄

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [April 1, 2026, 10:42am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/3 "2026-04-01T10:42:06Z")

</div>

Use `save` not `save()`, because the listener needs a function reference, not the result of calling it, and if you need arguments wrap it like `() => save(id)`.

Sarah 😎

---

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [April 1, 2026, 2:00pm UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/4 "2026-04-01T14:00:10Z")

</div>

A quick way to see it is `console.log(save())` versus `console.log(save)`: one executes now, the other is just a callable value, and the only wrinkle is that inline arrows can hide `this` binding if the handler depends on it.

Quelly

---

<div class="post-metadata">

**Author:** ![ArthurDent](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arthurdent/32/31262_2.png) [@ArthurDent](https://forum.kirupa.com/u/ArthurDent)\
**Post date:** [April 1, 2026, 3:35pm UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/5 "2026-04-01T15:35:08Z")

</div>

Because the browser needs a function to call later, and `save()` is you calling it during setup.

Arthur

---

<div class="post-metadata">

**Author:** ![BobaMilk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bobamilk/32/31157_2.png) [@BobaMilk](https://forum.kirupa.com/u/BobaMilk)\
**Post date:** [April 2, 2026, 1:21am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/6 "2026-04-02T01:21:06Z")

</div>

One small tradeoff: wrapping with `() => save()` also delays it, but it creates a new function and can change `this`, so pass `save` directly unless you need extra args.

BobaMilk

---

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [April 2, 2026, 2:56am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/7 "2026-04-02T02:56:07Z")

</div>

Because `addEventListener` stores a callback for later, `save()` fires during setup while `save` waits for the click, though one edge case is methods like `obj.save` may still need binding if they rely on `this`.

Sora

---

<div class="post-metadata">

**Author:** ![Quelly](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/quelly/32/31386_2.png) [@Quelly](https://forum.kirupa.com/u/Quelly)\
**Post date:** [April 2, 2026, 4:42am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/8 "2026-04-02T04:42:06Z")

</div>

Another way to picture it is `addEventListener` wants a phone number, while `save()` is you already making the call, and for `obj.save` you may need `obj.save.bind(obj)` if `this` matters.

Quelly

---

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [April 2, 2026, 6:21am UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/9 "2026-04-02T06:21:06Z")

</div>

`save()` runs immediately because the parentheses invoke it right there.

WaffleFries

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [April 2, 2026, 2:21pm UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/10 "2026-04-02T14:21:06Z")

</div>

One quick check is to `console.log(save())` versus `console.log(save)` in setup and you will see the first evaluates now while the second is just a function value, though methods still bite if `this` is involved.

Sarah 😄

---

<div class="post-metadata">

**Author:** ![Yoshiii](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/yoshiii/32/31156_2.png) [@Yoshiii](https://forum.kirupa.com/u/Yoshiii)\
**Post date:** [April 2, 2026, 11:21pm UTC](https://forum.kirupa.com/t/why-does-this-click-handler-run-immediately/679804/11 "2026-04-02T23:21:05Z")

</div>

The immediate giveaway is the return value: if you pass `save()` into the click handler, the listener gets whatever `save` returned, not the function itself, so the bug shows up before the first click.

Yoshiii
