Immediately Invoked Function Expressions (IIFE’s)

IIFE’s are quite simple to understand and apply. I haven’t run into too many times where their use was TOTALLY necessary, but it is a fundamental.

In a nutshell, the syntax of an IIFE is as such:

(function () {
return 1 * 8;
})();

To analyze this a bit, the first set of parentheses contains the anonymous function definition itself. The second set of parentheses INVOKE the function. Compare that to when you invoke a function normally:

(function () {
return 1 * 8;
})();
// versus
var sampleFunction = function () {
return 1 * 8;
};
sampleFunction();

The two are identical (not really).

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.