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

JavaScript

In the finally() method if i type 'event.target.remove()' without it being an arrow function what will happen ?

This isn't a problem so to speak. I'm just curious as to why adding an arrow function there is necessary

(PS this is a question for Asynchronous Programming with JavaScript 8th section)

1 Answer

Hi Alexander!

Not using an arrow function will throw the timing off.

In this case, you want to use a callback function (which delays execution of that function until an appointed time, in this case, not until finally() executes).

I recommend taking this course to fully understand how callback functions work and why you should use them:

https://teamtreehouse.com/library/callback-functions-in-javascript

Also, I came up with this to help better visualize how callback functions work:

const square = function(num) {
  return num * num;
}

const quad = function(func, num) { // func being the callback function as a perameter (a function variable)
  return func(num) * func(num);
}

console.log( quad(square, 3) ); // square being the callback function as an argument function

Which, in this case, will log 81 to the console.

Note in this case the execution of square is delayed until quad is called (hence its "callback"-ness!?!).

I hope that helps.

Stay safe and happy coding!