Other Cool

Some features of ES6…

While there are many features that are coming out in ES6 and ES7. There are few ones that are pretty easy to wrap your head around.

Let Operator
Using let operator instead of var operator you can define variable whose scope is defined inside any block scope, any curly brackets.

function a() {

  for (var i =0; i < 10; i++) {
    var b = i+1;
    let c = i;
  console.log(b); //will have a value
  console.log(c); //undefined error

One of the limits are that let variables can’t be redefined.

let a = 3;
let a = 5; //wrong.. error.


const is like const in any other programming languages, it’s used to defined constants, variables which are defined and assigned once can’t be redefined or reassigned.

In ES6, you have to assign value to const, whenever you declare it.
const is also block scoped, just like let. var is function scoped.

const PI = 3.14;
PI = 3.15; // gives error

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s