Created
July 5, 2022 06:15
-
-
Save samuraijane/0052949441e3ade7e6400eb4e58bf858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// callback functions can help us deal with asynchronous code but it can also get messy if we have multiple sequential callbacks (not shown here) | |
var shoppingList = ['apples', 'biscuits', 'cabbage']; | |
function addItem(item, callback) { | |
setTimeout(() => { | |
shoppingList.push(item); | |
console.log("Item added to shopping list"); | |
callback(); | |
}, 200); | |
} | |
function getAllItems() { | |
setTimeout(() => { | |
console.log('Shopping List Items:'); | |
console.log(shoppingList); | |
}, 100); | |
} | |
addItem('dip', getAllItems); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment