# not adding ()'s to function calls?

**URL:** https://forum.kirupa.com/t/not-adding-s-to-function-calls/639827
**Category:** web dev
**Created:** [May 17, 2019, 4:10pm UTC](https://forum.kirupa.com/t/not-adding-s-to-function-calls/639827 "2019-05-17T16:10:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Raph59](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@Raph59](https://forum.kirupa.com/u/Raph59)
#### Post date: [May 17, 2019, 4:10pm UTC](https://forum.kirupa.com/t/not-adding-s-to-function-calls/639827/1 "2019-05-17T16:10:35Z")

</div>

I have a different book saying this will work

```
window.onload = init;
function init() {
   var button = document.getElementById("addButton");
  button.onclick = handleButtonclick;
}

function handleButtonclick() {
 alert ("Button was clicked!");
}

```

**note** notice that when the functions are _called_ (at the top), there are no ()'s . You would expect this code to NOT run properly and yet (1) it DOES; (2) adding the ()'s TO the function calls do NOT work? I just came from K’s chapter on Functions --\> _A Simple Functions_ as a sanity check, and sure enough “you function needs to be called…” sayHello(); \<–

Thoughts appreciated. Thank yoU!!

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [May 17, 2019, 4:27pm UTC](https://forum.kirupa.com/t/not-adding-s-to-function-calls/639827/2 "2019-05-17T16:27:16Z")

</div>

> [@Raph59](#):
>
> button.onclick = handleButtonclick;

You don’t want to call `handleButtonclick()` here. This is the init step, when things are getting initialized. You want `handleButtonclick()` called when the button is clicked. To do this, you need to give the function - without calling it - over to the button so that when its clicked, it can call your function for you. This is why you’re not using `()` here. You just supply the function, by means of assigning to an `onclick` property, and when the button is clicked, it will internally take that function and call it for you, basically doing a `button.onclick(event)` where `event` is an automatically created object to describe the click event that occurred.
