课程: Mastering Web Developer Interview Code

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

What is a callback and how do you use it?

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…

内容