CodePeek
Practice / ArraysBack to CodePeek

JavaScript slice vs splice: One letter apart

Puzzle 9 of 15 · slice vs splice

Trace slice and splice on the same array of letters. Predict both logs by following the returned copy and any changes to the original. Choose an output below, then check the explanation. No signup needed. Browse puzzles by topic →

Arrays / slice vs spliceJavaScript
const letters = ["a", "b", "c"];
console.log(letters.slice(1).join(""));
letters.splice(1, 1);
console.log(letters.join(""));

Predict the console output. Each line is a separate log.

What’s the output?

Choose the output

Starter puzzles 15