callback functions
//Simple Calback
function makeASandwitch(meat, cheese, condiment, callback){
var sandwhich = "The sandwhich is " + meat + ' ' + cheese + ' and ' + condiment;
callback(sandwhich);
}
makeASandwitch('ham', 'swiss', 'BBQ sauce', function(sandwhich){
console.log(sandwhich);
});
//Optional Callback
function mySandwich(param1, param2, callback) {
alert('Started eating my sandwich.\n\nIt has: ' + param1 + ', ' + param2);
if (callback) {
callback();
}
}
mySandwich('ham', 'cheese');