[ { "category": "Functions", "title": "Rest parameters", "urlfrag": "Rest_parameters", "info": "
The rest parameter syntax allows us to create functions that take a variable number of arguments. In a way, rest syntax is like the opposite of `spread` syntax. `Spread` expands an array into its elements, while `rest` condenses elements into an array.
There are three main differences between rest parameters and the `arguments` object:
The rest syntax can also be used in array and object destructuring assignments.
", "code": "function f(a, b, ...theArgs) {\n //...\n}" }, { "category": "Operators", "title": "Spread syntax", "urlfrag": "Spread_syntax", "info": "Spread syntax expands or \"spreads\" iterables like arrays and objects.
Spread syntax can be used to
Function.prototype.apply
It is an alternative to
Object.createand
slice.", "code": "function sum(x, y, z) {\n return x + y + z;\n }\n const numbers = [1, 2, 3];\n sum(...numbers); // 6" }, { "category": "Expressions", "title": "Destructuring assignment", "urlfrag": "Destructuring_assignment", "info": "
The destructuring assignment syntax unpacks values from objects and assigns them to variables. It's somewhat similar to spread syntax because they both unpack values. It can be used with rest syntax.
", "code": "var [a, ...b] = [1, 2, 3]\n // a = 1\n // b = [2, 3]" }, { "category": "Object", "title": "Object.freeze()", "urlfrag": "Object.freeze()", "info": "The Object.freeze() method freezes an object. In other words, it prevents data mutation of the object passed into it.
", "code": "Object.freeze(obj)" }, { "category": "Functions", "title": "Default parameters", "urlfrag": "Default_parameters", "info": "Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed (MDN).
", "code": "function multiply(a, b = 1) {\n return a * b;\n }\n \n multiply(5);\n // 5" } ]