IIFE versus blocks
As ES5 did not provide block scope, a popular pattern to achieve block scope was to use immediately invoked function expressions (IIFE), for example:
(function () { var block_scoped=0; }()); console.log(block_scoped); //reference error
With ES6's support for block scopes, you can simply use a let
or const
declaration.