ES6 brings more amazing features to the JavaScript language.

So without any further ado, let’s dive right in to see what are they and how they can help you write code more efficiently.

1. Rest Parameters

Take a look at a built-in function in JavaScript:

Math.max(arg1, arg2, …, argN)

You can call that function with any number of arguments. Like:

let max1 = Math.max(3, 5, 5, 1); // 5

let max2 = Math.max(23, 1, 56, 23, 13, 67); // 67

Using ES6 rest parameters feature, you can define functions just like Math.max.

Here’s how:

function averageOf(…numbers) {
  let sum = 0;

  for (let number of numbers) {
    sum += number;
  }
  return sum / numbers.length;
}
let average = averageOf(5, 6, 2, 1); // 3.5

And that’s how the three dots (…) help you build special functions.

#coding #javascript #web-development #es6 #javascript-development

9 ES6 Features Every JavaScript Developer Should Know
2.00 GEEK