Callback Functions

function one(){
console.log('first');
}function two(){
console.log('second');
}one();
two();
//first
//second

How to create a Callback

I will show you how to create a callback function with the following example, you can do this with Chrome dev tools.

function vacation(city) {
alert(`Going to vacation in ${city} this weekend.`);
}
vacation('Miami');// Alerts: Going to vacation in Miami this weekend.
function vacation(city, callback) {
alert(`Going to vacation in ${city} this weekend.`);
callback();
}
vacation('Miami', function() {
alert('Vacation is over, back to work');
}
);
function vacation(city, callback) {
alert(`Going to vacation in ${city} this weekend.`);
callback();
}
}function alertDone(){
alert('Vacation is over, back to work');
}vacation('Miami', alertFinished);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store