Skip to main content
JavaScript Output Prediction Medium +20 XP

Spread Operator

What is the result?

JavaScriptRead-only
const a = [1, 2];
const b = [0, ...a, 3];
console.log(b.length);

What is the output?

Show answer and explanation

Answer: 4

Spread expands [1,2] inline: [0, 1, 2, 3] has 4 elements.

Hint: Count how many elements end up in the array.

What this challenge tests

Output Prediction in JavaScript: spread, arrays.

Related challenges