How to write a self invoked function in JavaScript

Self invoked functions are function that run on themselves without need to be called, the syntax to create self invoked functions is as follows;

(function(){
    // function body
})()


the runtime will run everything in a self invoked function's body
You can pass parameters to the function using the syntax below;



(function(params){

    // function body

})(params)

parameters will be made available to the function as any other argument

Comments

Popular posts from this blog

FlappingBird Postmortem (JS13K)

JavaScript introduction to variables

FlappingBird JS13K Games

How to target all elements of a given class name in JavaScript

Zedplug will be decommissioned on November 30th