"I will finish later!"
Asynchronous is functions running in parallel with other functions
In the real world, callbacks are most often used with asynchronous functions.
function myFunction( text, callback ) {
console.log( text )
/* --- */
/*
call callback function
*/
callback( 'text from myDisplayer (as callback function)' )
}
function myDisplayer( text ) {
console.log( text )
}
/*
call myFunction
myDisplayer passed into myFunction as an argument function
*/
myFunction( 'text from myFunction', myDisplayer )
/* --- */
// text from myFunction
// text from myDisplayer (as callback function)
Example
Note
When you pass a function as an argument, remember not to use parenthesis.
Right: myFunction( 'text from myFunction', myDisplayer )
Wrong: myFunction( 'text from myFunction', myDisplayer() )
Top comments (0)