ES6 major features

Arrow and Spread

This is a brief summary for the ES6 features.


Arrow Function

  (parameters)=>{
    console.log("comments");
  }

It is different with regular function in JavaScript that is an alternative way to address the this scope problem.

Many JavaScript developer should face the this scope issue. We can use arrow function keep the this point and stick to its parent.

More…

Spread Operator

  let arrayA = [1,2,3];
  console.log(...arrayA); // result: an array
  
  let arrayB = ['Tom','Jerry'];
  console.log(...arrayB); // result: Tom Jerry
  
  let arrayC = ['I','go','to'];
  let arrayD = [...arrayC,'school','by','bus'];
  console.log(...arrayD); // result: I go to school by bus

It is simple and useful for combine multiple arrays.

In the past, people can use concat to combine these two arrays but spread operator do it more directly.

Tags: JavaScript
Share: Twitter Facebook LinkedIn