Before ES6 came out in 2015, JavaScript had not concept of modules and thus code outside of functions just became global. The immediately invoked function expression (or IIFE) was the solution to this.
Prepping for your frontend interviews? Use code "conner" for a discount on my course FrontendExpert:
https://www.frontendexpert.io/conner
Socials:
TikTok: / connerardman
LinkedIn: / connerardman