Does your JavaScript code still need IIFEs and explicit strict mode?

At a time when modules are becoming a de facto architectural solution for any serious frontend JavaScript codebase, and ES6 is at our doorstep, one may wonder if a systematic use of IIFEs and explicit strict mode declaration (using 'use strict';) is still relevant. This short note is thus designed to answer these questions.

Note: if you aren't using modules yet (should it be with CommonJS or the native ES6 syntax supported by Babel), you should really begin to! In both cases, Browserify is the way to go. Other solutions exist, of course, but these two respectively are the current (at least in the node.js world) and upcoming standard, and are the most broadly used.

Here we go:
  • A module's code does not need to be wrapped in an IIFE, as it is already in isolation anyway
  • 'use strict'; is still needed in CommonJS modules, nothing new here; on the contrary, it is implied in ES6 modules
  • 'use strict'; is needed in your code's entry point, which thus must also be wrapped in an IIFE to prevent concatenation side-effects

I hope this helped you know what you still have to do to keep your JS tidy as of today.