Rest Parameter
In JavaScript, the rest parameter allows functions to accept an arbitrary number of arguments as an array, simplifying variable parameter handling and manipulation.
Syntax:
//... is the rest parameter (triple dots)
function functionname(...parameters) {
statement;
}
Example: In this example, the sum function accepts an arbitrary number of arguments using the rest parameter …numbers.
Javascript
function sum(...numbers) { let total = 0; for (const num of numbers) { total += num; } return total; } console.log(sum(1, 2, 3)); |
Output
6
JS 2015 or ECMAScript 6 (ES6)
JS 2015 (ES6) also known as ECMAScript 6 (ES6), ECMAScript 6 (ES6) is a significant update to JavaScript, introducing arrow functions, classes, template literals, let and const for variable declaration, enhanced object literals, destructuring, and more modern features for better code organization and readability.