As I delve into learning Angular, I've encountered a recurring snippet in the app.js
file across various resources:
(function () {
\\\myAngularModules
})();
Despite its prevalence, the explanation provided is often just "it's just good practice."
Queries:
- Why is enclosing our Angular JS code within a function considered good practice?
- What type of function is it and what is its purpose?
Please illuminate with examples wherever feasible.