...)The three dots (...) in modern JavaScript are used for two distinct, powerful features depending on context: the Rest Parameter (collecting items into an array) and the Spread Operator (unpacking items from an iterable).
+-----------------------------------------------------------------------------+
| REST PARAMETER (Collects multiple items into ONE single array) |
| Context: In function parameter lists or destructuring patterns |
| Example: function sum(...numbers) { ... } |
+-----------------------------------------------------------------------------+
vs.
+-----------------------------------------------------------------------------+
| SPREAD OPERATOR (Expands ONE array/object into individual elements) |
| Context: In function calls, array literals, or object literals |
| Example: Math.max(...numbers) | [...arr1, ...arr2] |
+-----------------------------------------------------------------------------+original using Spread?...rest) be placed in a function's parameter list?const obj1 = { a: 1, b: 2 }; const obj2 = { b: 99, c: 3 }; const merged = { ...obj1, ...obj2 };, what is the value of merged.b?[..."MSK"] evaluate to?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Arrow Functions Advanced | Closures Introduction |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.