What is the purpose and usage of the Spread Operator in JavaScript?
Instruction: Define the Spread Operator and provide examples of its applications.
Context: This question aims to assess the candidate's familiarity with ES6 syntax, specifically the Spread Operator, and its use cases in making code more concise and readable.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Spread syntax has related but distinct uses. In an array literal or function call, it expands an iterable into elements or arguments. In an object literal, it copies an object's own enumerable properties into the new object; later properties overwrite earlier ones with the same key.
const first = [1, 2]; const combined = [...first, 3, 4]; const settings = { theme: "light", nested: { enabled: true } }; const changed = { ...settings, theme:...