2 min read

ECMAScript 2015 - ES6

ECMAScript 6 was the second major revision to JavaScript.ECMAScript 6 is also known as ES6 and ECMAScript 2015.This chapter describes the most important features of ES6.
ECMAScript 2015 - ES6

New Features in ES6

  • JavaScript Arrow Functions
  • JavaScript For/of
  • JavaScript Classes
  • JavaScript Promises
  • Default Parameters

JavaScript Arrow Functions: Arrow functions allows a short syntax for writing function expressions.

You don't need the function keyword, the return keyword, and the curly brackets.


// ES5
var x = function(x, y) {
return x * y;

// ES6
const x = (x, y) => x * y;

The For/Of Loop

The JavaScript for/of statement loops through the values of an iterable objects.

for/of lets you loop over data structures that are iterable such as Arrays, Strings, Maps, NodeLists, and more.


var cars = ["BMW", "Volvo", "Mini"];
var x;

for (x of cars) {
 document.write(x + "<br >");

JavaScript Classes

JavaScript Classes are templates for JavaScript Objects.Use the keyword class to create a class.Always add a method named constructor().A JavaScipt class is not an object.


class ClassName {
 constructor() { ... }

JavaScript Promises

A Promise is a JavaScript object that links "Producing Code" and "Consuming Code".

"Producing Code" can take some time and "Consuming Code" must wait for the result.


let myPromise = new Promise(function(myResolve, myReject) {
// "Producing Code" (May take some time)

 myResolve(); // when successful
 myReject();  // when error

// "Consuming Code" (Must wait for a fulfilled Promise).
function(value) { /* code if successful */ },
function(error) { /* code if some error */ }

Default Parameter Values:ES6 allows function parameters to have default values.

function myFunction(x, y = 10) {
// y is 10 if not passed or undefined
return x + y;
myFunction(5); // will return 15

JavaScript ES6

#JavaScript #ES6 #ECMAScript #Promise #Probyto #ProbytoAI

Subscribe and follow us for latest news in Data Science and Machine learning and stay updated!

Facebook: https://facebook.com/probyto
Twitter: https://twitter.com/probyto
LinkedIn: https://linkedin.com/company/probyto
Instagram: https://instagram.com/probyto