Sometimes, we want to name a JavaScript function and execute it immediately.
In this article, we’ll look at how to name a JavaScript function and execute it immediately.
How to name a JavaScript function and execute it immediately?
To name a JavaScript function and execute it immediately, we can use an IIFE.
For instance, we write
(function addEventsAndStuff() {
//...
})();
to define the addEventsAndStuff
function and then call it immediately by wrapping it in parentheses.
And then we call it with ()
.
Conclusion
To name a JavaScript function and execute it immediately, we can use an IIFE.