Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

function and dom

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

Cooper Runstein
Cooper Runstein
11,837 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