Predict Spread Operator
Predict Output Easy
Question
What does this code print?
Code
const a = [1, 2];
const b = [3, 4];
const combined = [...a, ...b];
console.log(combined);
Hint
Spread expands array elements into the new array.
Explanation
The spread operator ... expands an array's elements into the enclosing array literal. [...a, ...b] is equivalent to [1, 2, 3, 4]. This creates a new array — the originals a and b are not modified.
Related Resources
Related Lessons
- JavaScript Arrays
Learn about the spread operator.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.