JSFiddle - React, Tailwind, and code Playground
HTML
block scope
lexical scope
capture a variable
declare a variable
define a variable
JavaScript
const allproducts = [1, 2, 3, 4];
for (let i = 0; i < allproducts.length; i++) {
console.log('value of i', i);
foo(function() {
console.log('INSIDE CALLBACK VALUE OF i', i);
});
}
console.log('value of i outside of loop', i);
function foo(callback) {
setTimeout(() => {
callback();
}, 0);
}
console.log('END OF CODE');