Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


function and dom

alertbox.addEventListener("click" , ()=>{ what is the use of arrow function here?

Cooper Runstein
Cooper Runstein
11,850 Points

Are you asking what the function's purpose is, or are you asking specifically why an arrow function was used?

what is the purpose of function

1 Answer

You define the purpose of a function. You create them or use them how you see fit.
If you define nothing it will do nothing, if you make it run loops of specific code it wil loop your code.

function doSomething (x) {
 return  x*2;
doSomething(4); // returns 8
// Anonymous functions have no name, you just push into it the code it needs to run there and then.
document.addEventListener("click", function(){
    document.getElementById("demo").innerHTML = "Hello World";

Hope this helps, Cc