A coder's digest that is trying to be quirky, flawed and an enormous success.

Quickie on ES6

by Zubair Ahmed on October 6, 2016

A quick overview of the new functionalities that are being shipped with ES6

There has been an inception of the 6th edition of the language and here is a quickie for the noobs

As you might already know that JavaScript is an implementation of the general purpose client-side scripting language specification called ECMAScript. There has been an inception of the 6th edition of the language and here is a quickie for the noobs, if you know it please move along:

I have “cheery-picked” a few features to get yourself introduced to the new capabilities it provides a developer:

let

The new standard introduces the new let keyword, which lets you declare and initialize variables in the scope of a block. A block can be a programmatic enclosure such as a statement, an expression or function.

for(leti=0;i<100;i++){console.log(i);}if(x!=y){leti=x*y}

Using the let keyword leads to cleaner, more scope controlled and usable code. The difference between let and var is in the scope, for example a local variable defined by the var keyword can be used in the entire enclosing function, while variables defined by let only work in their own block.

const

As you might expect from the sound of the keyword itself that it makes it possible to declare constants ( immutable variables).

Though, constants cannot be considered to be fully immutable, because if the constant holds an object the properties and methods can still be altered

=>

This featues let us write anonymous functions in a better manner. Instead of writing the function keyword we can removed it with the =>. This automatically return the resolved value of the statement that comes right after.

value=(a,b)=>a+b;//which is the same asvarvalue=function(a,b){returna+b;};

…

ES6 comes with a new operator called spread signified by …, which is generally a sign to place multiple expected items. A better way to understand it is by an example where you add or spread an array to include more elements.

I guess this has to be one of the best features of ES6. Just like what you have done with AMD using RequireJS before, now ES6 comes with modules as native features. The idea here is to define each module in its own file, then use to “export” it out to other files, and accordingly “import” them from other files.

//otherController.jsfunctioncallName(a){return'He is '+a;}functioncallRealName(a){if(a=='Palpatine'){return'He is Sidious';}else{return'He is not Sidious';}}export{callName,callRealName}//mainController.jsimport{callName,callRealName}from'otherController';console.log(callName('Anakin'));console.log(callName('Palpatine'));

I guess that was good enough to get started.

Here is a good documentation for most of the features if you would like to dwell into ES6 further

Plus, here is a compatibility chart, which I believe is really import to keep a track on to know exactly when is the “future”.