From the course: Mastering Web Developer Interview Code

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

What is a callback and how do you use it?

What is a callback and how do you use it?

From the course: Mastering Web Developer Interview Code

What is a callback and how do you use it?

- [Instructor] A callback is a convention in JavaScript that is often used with asynchronous programming. So that's a common question that you'll get in an interview to explain and then maybe provide an example of how it works. So let's take a look. And as I mentioned, callbacks are used to do things asynchronously, or whenever you want to execute code not necessarily in order, but at a certain point in time or when an event takes place. Now, because of this, they're used often in events to take care of tasks, whenever the events are triggered. Callbacks often use the anonymous function, which means a functions with no names, because they're invoked immediately once the event takes place, so there's no need for a name. So let's take a look at an example of how it works, and what we're going to do, is do a slightly different version of what we did in the previous episode. Where we did some tips that would hover whenever you…

Contents