An item you put on your to-do list and then do right away.
Normal function:
An item you put on your to-do list and you'll get to it later.
An IIFE is nothing more than a function that is called once and it's called right away.
They used to be big back in the day to avoid variable scoping issues:
// app.jsvarsecret='123';
The above secret variable is in the window scope, so it is accessible anywhere in the runtime. Changing to use an IIFE, it put the variable in the function's scope, meaning it cannot be accessed outside the function:
// app.js(function(){varsecret='123';})();// I can't see `secret` down here!!
IIFE:
An item you put on your to-do list and then do right away.
Normal function:
An item you put on your to-do list and you'll get to it later.
An IIFE is nothing more than a function that is called once and it's called right away.
They used to be big back in the day to avoid variable scoping issues:
The above
secret
variable is in thewindow
scope, so it is accessible anywhere in the runtime. Changing to use an IIFE, it put the variable in the function's scope, meaning it cannot be accessed outside the function:`
Thanks for the explanation. Your approach with a to-do list is just great!