Skip to content

Instantly share code, notes, and snippets.

@duggiemitchell
Last active February 1, 2016 19:00
Show Gist options
  • Save duggiemitchell/96aa12251c8b894d4aa8 to your computer and use it in GitHub Desktop.
Save duggiemitchell/96aa12251c8b894d4aa8 to your computer and use it in GitHub Desktop.
ES2016 Reference Sheet &Translations

Declarations

Using let Defines new variables scoped to the nearest block in which it has been declared, without affecting like-named variables outside of the block scope. Variables using let are not hoisted to the top They cannot be redeclared

//before:
var foo = 'bar';
//ES2015
let foo = 'bar';

Using const Clears up confusion with magic numbers, const creates a read-only named constants. Cannot be redefined Must have an initial value Scoped to the nearest block and shares similar behaviors as let

///Before:
var luckyNumber = 7;
//ES2015:
const LUCKY_NUMBER = 7;

Functions

Variatic Functions Using rest parameters Using spread operator **Arrow Functions or lambdas **:

// Before:
let printName = function(value){
  console.log( value );
}
// ES2016:
let printName = (value) => {
console.log(value);
}

Objects & Strings

Object Instantiation Syntax Object Initializer Shorthand Object Destructuring Shorthand The new object initializer shorthand and object destructuring look very similar, but they are used in different scenarios.* Method Initializer Shorthand String Template & Interpolation

Object.assign

Destructuring & Assigning for...in

Arrays

Maps

Sets

let tags = new Set();

tags.add("JavaScript");
tags.add("Programming");
tags.add("Web");

for( let tag of tags){
  console.log(`Tag: ${tag}`); //logs "Tag: JavaScript" "Tag: Programming" "Tag: Web"
}

Using Array desctructuring to extract the first element in tags and assign to the variable first:

let tags = new Set();
tags.add("JavaScript");
tags.add("Programming");
tags.add("Web");
let [first] = tags;
console.log( `First tag: ${first}` );// logs: "First tag: JavaScript"

The WeakSet is a more memory efficient type of Set where only objects are allowed to be stored.

Classes & Modules

Promises Iterators & Generators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment