A callback is a function that you pass in as a variable to another function. A typical example in JavaScript is the setTimeout function. If you want something to execute after a delay, you can pass it as a callback to setTimeout.
setTimeout will wait 1 second (1000 milliseconds) and then it will actually call sayHello. The result is that "Hello there!" will get printed to the console after one second.
Because it takes a function as an argument, setTimeout is called a "higher order function."
A callback is a function that you pass in as a variable to another function. A typical example in JavaScript is the
setTimeout
function. If you want something to execute after a delay, you can pass it as a callback tosetTimeout
.setTimeout
will wait 1 second (1000 milliseconds) and then it will actually callsayHello
. The result is that "Hello there!" will get printed to the console after one second.Thanks :)