IIFE scope
global function block level
by trentHarlem
JavaScript
//console.log('0 Outside Above the function',' scope i is: ', i);
// i is not defined
(function chicoIIFE() {
let i = 'global scope'
console.log('1 Outside Above the function', ' scope i is: ', i);
function checkScope() {
let i = 'function scope';
console.log('2 inside the function', ' scope i is: ', i);
if (true) {
let i = 'block scope';
console.log('3 inside the block', ' scope i is: ', i);
if (true) {
let i = 'nested block scope';
console.log('4 inside the nested block', ' scope i is: ', i);
}
}
console.log('5 inside the function below the block', ' scope i is: ', i);
return i;
}
console.log('6 Outside below the function before the call', 'scope i is: ', i);
checkScope()
console.log('7 Outside after the function after the call ', 'scope i is: ', i);
})()