Deanna Tran 338d7ee8a7 Change "rest operator" to say "rest parameter" in challenges and guide (#35496)
* change es6 challenges rest operator to param

* fix rest parameter typos

* change rest operator to parameter in guide

* fix casing

* change rest operator to rest parameter in guide

* change rest operator to rest parameter in curriculum

* remove extra whitespace

* remove whitespaces

* remove whitespace

* fix: removed arabic file

* fix: removed chinese file
2019-05-08 16:30:24 +02:00

1.3 KiB

title
title
Use the Rest Parameter with Function Parameters

Use the Rest Parameter with Function Parameters

Rest parameter explanation

Mozilla Developer Network

Spread operator compared to rest parameter

Stack overflow

Video explaining spread and rest

Image of youtube video link spread and rest parameter

Example

This code

const product = (function() {
	"use strict";
	return function product(n1, n2, n3) {
		const args = [n1, n2, n3];
		return args.reduce((a, b) => a * b, 1);
	};
})();
console.log(product(2, 4, 6));//48

Can be written as such

const product = (function() {
	"use strict";
	return function product(...n) {		
		return n.reduce((a, b) => a * b, 1);
	};
})();
console.log(product(2, 4, 6));//48