Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In this video we'll take a look at what a callback looks like with some example syntax.
Callback Syntax
Given the following code...
function everySecond(callback) {
// This function runs the callback every second
}
function getStockData() {
// This function gets stock data from the NYSE
}
everySecond(getStockData);
...the getStockData
function is a callback function since it's being invoked by the everySecond
function. Callbacks are just regular functions used by another function at some other time in the future. This can be at regular intervals or from user interaction.
The easiest way to spot a callback is if it has the name of a function and is being passed into another function call.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up