An Immediately Invoked Function Expressions (IIFE) is a JavaScript function that runs as soon as it is defined. Since the keyword function does not come first, it is a function expression and not a function declaration.

See the Pen thecodelog.com - JS IIFEs 1 by Deano (@deangilewicz) on CodePen.

IIFEs accept parameters just like other functions.

See the Pen thecodelog.com - JS IIFEs 2 by Deano (@deangilewicz) on CodePen.

The result of an IIFE can be assigned to a variable.

See the Pen thecodelog.com - JS IIFEs 3 by Deano (@deangilewicz) on CodePen.

With a named IIFE the identifier (name) is found only in the enclosing scope, not in the outer scope. Hiding the name inside itself means it does not pollute the enclosing scope unnecessarily.

See the Pen thecodelog.com - JS IIFE 4 by Deano (@deangilewicz) on CodePen.