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 trialRamesh Kunwar
Courses Plus Student 4,066 Pointsfunction and dom
alertbox.addEventListener("click" , ()=>{ what is the use of arrow function here?
Ramesh Kunwar
Courses Plus Student 4,066 Pointswhat is the purpose of function
1 Answer
Chloé Claes
19,451 PointsYou 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
Cooper Runstein
11,850 PointsCooper Runstein
11,850 PointsAre you asking what the function's purpose is, or are you asking specifically why an arrow function was used?