Skip to content

Instantly share code, notes, and snippets.

@subzey
Created January 15, 2016 20:04
Show Gist options
  • Select an option

  • Save subzey/7d71e2ecbf102c88087a to your computer and use it in GitHub Desktop.

Select an option

Save subzey/7d71e2ecbf102c88087a to your computer and use it in GitHub Desktop.
The ES6 way to IIFE
'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