Grokking Advanced JavaScript
0% completed
Self-Invoking Functions
A web page that loads two scripts can break even when each script works correctly alone. If both scripts declare a top-level variable named count, they share one global scope, so the second declaration either overwrites the first value or, with let and const, throws a SyntaxError for a duplicate name. Each script needs a scope of its own for its private variables.
A function provides such a scope, but a normal function runs only when something calls it
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%