1. Home
  2. Javascript
  3. Self invoking function

Self invoking function lets you immediately execute code. Another benefit is scoping, so you are not risking cluttering the global object. It's also a good practice to check for the window object and other dependencies by passing them as arguments.

#javascript
(function(){

    // Place your code here
    
})(window) // Ensure that the window object is available before executing the code.
copy
Full Javascript cheatsheet