Skip to content

Instantly share code, notes, and snippets.

@samuraijane
Created July 5, 2022 05:32
Show Gist options
  • Save samuraijane/a5d5dbc363e000ca761e878ac0619d13 to your computer and use it in GitHub Desktop.
Save samuraijane/a5d5dbc363e000ca761e878ac0619d13 to your computer and use it in GitHub Desktop.
// 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