Created
January 15, 2016 20:04
-
-
Save subzey/7d71e2ecbf102c88087a to your computer and use it in GitHub Desktop.
The ES6 way to IIFE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; // V8 only can only use block scopes in strict mode so far. | |
| var a = 42; // Variables outside may be defined in any way you want. | |
| { // The block starts. Yeah, we can just start a new block anywhere we want. | |
| let a = 'Oh, hi!'; // Define a block scoped variable using let. | |
| console.log(a); // Use it. | |
| } // The block ends, and all the block scoped variables dies. | |
| console.log(a); // Left untouched. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment