From the course: JavaScript: Patterns
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
What is a callback and its role? - JavaScript Tutorial
From the course: JavaScript: Patterns
What is a callback and its role?
- [Instructor] Another term that you may have heard many times and not quite sure what it means is the callback. What is a callback and its role? In its simplest terms, a callback function is a function that is called inside of another function. In other words, whenever you pass a function in the arguments and run it inside the function, you're doing the callback pattern. Let me demonstrate. So we're back into Visual Studio Code in the index.js and what we're going to do is keep the calc function. And I'm simply going to change the return to four times four so we have a different number. And then what we're going to do is remove these two here and I'm going to create another function, like I said, we need to create a new function that we're going to call printCalc. And we're going to pass as the callback the argument callback. And it's going to make sense to you in a couple of seconds, so let's continue. And then let's…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.