Features with ES6

In 2015 the new standard of JavaScript was released and stabilized as ES6. It’s a new implementation for Javascript but you can use the ES6 standards with any scripting language like Typescript that is used as base for new Angular 2 and onward. While the first version of Angular was based on Js which left AngularJs with some loose ends, the Angular developers aimed to remove those in the next version of Angular by using typescript as base and re-defining the whole framework. Typescript provided many benefits that are now part of new Angular frameworks.

So lets see what important features were provided by ES6. It has many more but the below list of features are the most attractive & useful in my opinion –

Default Parameters

Template Literals

Multi-line Strings

Fat arrow Functions

Let & Const

Classes

1. Default Parameters – This doesn’t seems to be a very big enhancement but it’s quite a useful feature by ES6. If you did programming in js before you must have fought with checking the function parameters value in the code before performing any further operation on that data. But with ES6 you can initialize the parameters right on the function definition as default values for the parameters.

2. Template Literals – It is an old way of using expressions in your js file. Similarly like JSP allowed us to use java experessions within HTML. Using this way it saves developer’s time & effort of evaluating a value and performing some action based on that. Template literals are enclosed by back-ticks(` `) and syntax for using it is (${expression}).

3. Multi-line Strings – This is a cool feature that I like most, since if you had trouble formatting a long multi line string in past this is a savior. As I myself had a lot of tasks to perform using a long string say in email body or a notification message to user, code used to become a lot clumsy & hard to follow if your string is grwoing bigger and ES6 has catered this problem very well. See this example-

4. Fat arrow functions – The fat arrow function is a simplified and efficient way of writing functions in JS. As you can see in the code below fat arrow function not only allows us to reduce the size the code but also it reduces the overhead of scoping. With ES5 we used to bind the global scope with the function scope using self = this or .bind(this), but that is not required with ES6.

5. Let & Const – The variable declaration was the easiest in Js compared to any other language because there were no specific data types for any data requirement, just use var for any data. But with ES6 now we can define in 2 different types either let or const. So when do I use Let & Const in my code. Lets see this with an example

So as you have noticed the const are immutable & let are mutable data values. And both are block-scoped.

6. Class – Lastly the biggest of all – Classes, yes that is true now the same object-oriented programming (OOP) concept is available to use in scripting language. Now we can encapsulate the data & functions more effectively and make it public & private based on data sensitivity or program requirement. Though ES5 do had the class concept but it was not easy to develop so generally people have avoided that.

With ES6 the implementation is as simple as we used to do in any other OOP languages.