ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

What's the difference between slice and splice?

Quick answer

slice returns a copy of a portion without changing the original; splice mutates the array (removing/inserting) and returns removed items.

In detail

`arr.slice(start, end)` is non-mutating — great for copies and subarrays. `arr.splice(start, deleteCount, ...items)` mutates in place, removing and/or inserting, and returns the removed elements. Easy to confuse by name.

const a = [1, 2, 3, 4];
a.slice(1, 3);   // [2, 3]  — a unchanged
a.splice(1, 2);  // [2, 3]  — a is now [1, 4]

Why interviewers ask this: A naming-confusion check that catches sloppiness.

This is 1 of 118+ questions in the JavaScript Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the JavaScript Interview Kit → ₹299

Full kit

JavaScript Interview Kit · ₹299

Get it →