# What is being passed in the function!

**URL:** <https://forum.kirupa.com/t/what-is-being-passed-in-the-function/645602>\
**Category:** programming\
**Created:** [January 6, 2021, 4:11pm UTC](https://forum.kirupa.com/t/what-is-being-passed-in-the-function/645602 "2021-01-06T16:11:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Belfry777](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/belfry777/32/12917_2.png) [@Belfry777](https://forum.kirupa.com/u/Belfry777)\
**Post date:** [January 6, 2021, 4:11pm UTC](https://forum.kirupa.com/t/what-is-being-passed-in-the-function/645602/1 "2021-01-06T16:11:02Z")

</div>

Hello there,  
I have been working in the book by Kirupa Chinnathambi (JavaScript: absolute beginner’s guide, **chapter 11, console logging basics** ), and have a question regarding this piece of code below. I am thinking that argument “e” is the button, but I am not sure. Thanks for your help!  
Note: doSomething is referenced here:

```auto
myButton.addEventListener("click", doSomething, false);

function doSomething(e) {
            counter++;
            //console.log("We clicked on " + e.target.id);
            
            console.log("Button clicked " + counter + " times");
            
            if (counter == 3) {
                showMore();
            }
        }

```

---

<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:** [January 6, 2021, 9:16pm UTC](https://forum.kirupa.com/t/what-is-being-passed-in-the-function/645602/2 "2021-01-06T21:16:13Z")

</div>

`e` represents the Event object. Event objects are passed into functions used as event handlers when given to `addEventListener()`. Depending on what kind of event it is, it could have different properties associated with it. Common kinds of event objects are MouseEvent objects and KeyboardEvent objects. You can find more about them here:

- [https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
- [https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent)

The button itself is represented by `e.target` using the `target` property of the Event object. This is the element that triggered the event in the first place. Another common property is the `e.currentTarget` property which is the element `addEventListener()` was called from (in this case `myButton`). Note that these may not always be the same. Because events bubble, elements deeper in the hierarchy may trigger an event that get picked up by listeners higher in the hierarchy. In that case, target and currentTarget would be different. Here, since the button has no child elements of its own, both target and currentTarget in the Event object will both refer to the button element.

```
console.log(e.target === myButton); // true
```
