1. Home
  2. Javascript
  3. Self invoking function

Self invoking function lets you immediately execute code. Another benefit of it is scoping, so your not risking cluttering the global object. It's 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
NordVPN NordVPN