Bisexual Pride

In his post The anatomy of an immediately-invoked function expression, my friend Chris Ferdinandi shows you how he writes an IIFE from scratch. Here’s another way to approach it.

I start with a leading semicolon, two sets of parentheses, and a closing semicolon.


Then, I take my anonymous function:

function () {


And drop it into the first set of parentheses:

;(function () {


Boom. You’re good to go!

I also opt into strict mode to make my IIFE more bulletproof:

;(function () {

"use strict";

// Your code goes here...


If you want to learn more, I recommend the following in addition to Chris’ resources: