# Why are functions done this way in the app lab?

**URL:** <https://forum.code.org/t/why-are-functions-done-this-way-in-the-app-lab/36033>\
**Category:** CS Principles\
**Tags:** applab\
**Created:** [March 17, 2022, 1:00pm UTC](https://forum.code.org/t/why-are-functions-done-this-way-in-the-app-lab/36033 "2022-03-17T13:00:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![techtech136](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@techtech136](https://forum.code.org/u/techtech136)\
**Post date:** [March 17, 2022, 1:00pm UTC](https://forum.code.org/t/why-are-functions-done-this-way-in-the-app-lab/36033/1 "2022-03-17T13:00:20Z")

</div>

For instance in the app lab this is how functions are called:

onEvent(“button1”, “click”, function() {  
checkCorrect(“button1”);  
});

* * *

However isn’t the standard format in javascript: function functionName { };

Also why is there a parenthesis at the end of the entire function as well?

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [March 17, 2022, 2:01pm UTC](https://forum.code.org/t/why-are-functions-done-this-way-in-the-app-lab/36033/2 "2022-03-17T14:01:13Z")

</div>

This is an onEvent block that is calling a function when button1 is clicked. The function is a parameter of the onEvent block. The ending parenthesis is for the parameter list.

---

<div class="post-metadata">

**Author:** ![techtech136](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@techtech136](https://forum.code.org/u/techtech136)\
**Post date:** [March 17, 2022, 2:10pm UTC](https://forum.code.org/t/why-are-functions-done-this-way-in-the-app-lab/36033/3 "2022-03-17T14:10:30Z")

</div>

Ah I see, so is onEvent a built-in function from [code.org](http://code.org)?

So you are saying that functions can take another function as a parameter? If onEvent is a function.

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [March 17, 2022, 2:29pm UTC](https://forum.code.org/t/why-are-functions-done-this-way-in-the-app-lab/36033/4 "2022-03-17T14:29:06Z")

</div>

Yes, functions can be passed as parameters. Here is an [article](https://stackoverflow.com/questions/13286233/pass-a-javascript-function-as-parameter) I found that may help. 🙂
