Created
July 5, 2022 05:32
-
-
Save samuraijane/a5d5dbc363e000ca761e878ac0619d13 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
// without a callback, asynchronous code has unexpected results | |
var shoppingList = ['apples', 'biscuits', 'cabbage']; | |
function addItem(item) { | |
setTimeout(() => { | |
shoppingList.push(item); | |
console.log("Item added to shopping list"); | |
}, 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