Learning ES6!

A walk through the ES6 valey


Prototypes

Changes added to prototypes

Syntax

Changes on ES6 syntax and new tokens

Let vs Var

Block-Scoped variables

function () {
    var x = 1;

    if (x) {
        let y= x;
        let x= "X";
        y++;
    }
    console.log(x); // 1
    console.log(y); // Error: y is not defined
}

// there is no hoist
function () {
    console.log(foo); // ReferenceError
    let foo = 2;
}

// very good to use in loops
var i=0;
for ( let i=i ; i < 10 ; i++ ) {
    console.log(i);
}
// here, i is gone

// not very good to use with switch
switch (x) {
  case 0:
    let y= 'was 0';
    break;

  case 1:
    let y= 'was 1'; // TypeError for redeclaration.
    break;
}

// do not use this yet(let-block)
var x = 5;
var y = 0;

let (x = x * 2, y = 5) {
    console.log( x + y ); // 15
}
console.log(x, y); // 5, 0

            

Template String

for...of

Shorthand object notation

Arguments

Arrow Functions

Features

New features added to ES6

Generators

Promises

Classes

felipenmoura.org
@felipenmoura
fb.com/felipenmoura