# Spot the bug - #73

**URL:** <https://forum.kirupa.com/t/spot-the-bug-73/682400>\
**Category:** web dev\
**Created:** [July 2, 2026, 7:01am UTC](https://forum.kirupa.com/t/spot-the-bug-73/682400 "2026-07-02T07:01:16Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [July 2, 2026, 7:01am UTC](https://forum.kirupa.com/t/spot-the-bug-73/682400/1 "2026-07-02T07:01:16Z")

</div>

Quick one: event handling bug here.

```js
const button = document.querySelector('#save');
button.addEventListener('click', saveForm());

function saveForm() {
  console.log('saved');
}

```

Reply with what is broken and how you would fix it.

---

<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:** [July 3, 2026, 8:00am UTC](https://forum.kirupa.com/t/spot-the-bug-73/682400/2 "2026-07-03T08:00:28Z")

</div>

You’re calling `saveForm()` immediately and passing its return value (`undefined`) to `addEventListener`, so the click has nothing to run. Fix is to pass the function reference (or wrap it), and while you’re at it, make it accept the event if you’ll need it:

```auto
const button = document.querySelector('#save');
button.addEventListener('click', saveForm);

function saveForm(e) {
  console.log('saved');
}

```

Mechanism-wise: `addEventListener` stores a callback to invoke later; parentheses mean “run now, ” which is the opposite of what you want here. I found a related kirupa. com article that can help you go deeper into this topic:
