JS Logo

ECMA6 / ES6

The next JavaScript

by Vineesh N P / @vineeshvalsalan

JavaScript

Devloped by Brendan Eich in 1995

Appeared on Netscape Navigator 2.0

Submitted to ECMA in 1996

ActionScript and JScript has derrived from this

Versions

ES4 2007

ES5 2009

ES6 2013

Where can I test ES6

babel

Its a transpiler which converts es6 to es5

Lets take a look at some features

through example

CONST

							
const pi = '3.14';
pi = 3.14159265359 //error you can not change the value of constant
							
          

LET

Enables block scoping

							
(function(flag){
if(flag){
  let x = 10
  console.log(x) //x is 10
}
console.log(x) // x is undefined
})
							

Inheritance

              
class Vehicle {

  constructor (name, type) {
    this.name = name;
    this.type = type;
  }

  getName () {
    return this.name;
  }

  getType () {
    return this.type;
  }

}
class Car extends Vehicle {

  constructor (name) {
    super(name, 'car');
  }

  getName () {
    return 'It is a car: ' + super.getName();
  }

}
let car = new Car('Tesla');
console.log(car.getName()); // It is a car: Tesla
console.log(car.getType()); // car
              

Better itrations

lets forget for(i ; i < blah ; i ++)

							
var planets = ['Mercury', 'Venus', 'Earth', 'Mars'];

planets.forEach(function(planet){
  console.log(planet)
})
//or

for(var planet in planets){
  console.log(planet)
}
							

Fat Arrows

Writing functions

								
function myFunction(){
  console.log("hello wolrd!")
}

() => {
  console.log("Hello world!")
}

var myFunction = function(){
  console.log("Hello world!")
}

var myFunction = () => {
  console.log("Hello world")
}
								

With parameters

									
function sum(a, b){
  return a+b;
}

var sum = (a,b) => {
  return a+b
}

var sum = (a, b) => a+b //automatically implies return
									

set and get

Enables block scoping

					         
class Car {
  constructor (name) {
    this._name = name;
  }

  set name (name) {
    this._name = name;
  }

  get name () {
    return this._name;
  }
}
let car = new Car('Tesla');
console.log(car.name); // Tesla
car.name = 'BMW';
console.log(car.name); // BMW
  							

Apart from this

Default function parameter

collections

maps , its a kind of key value pair storing

modules, export and import

Easy?