Skip to solution
mediumFrontend

What does the delete operator do?

489 views
01

Understand the problem

Question presented to candidate: "If I have an array [1, 2, 3] and run delete arr[1], what does the array actually look like afterward — and is that different from what array.splice would have done?"

What a strong answer should cover:

  • 📌 Interview term: delete — removes a property entirely from an object (the key genuinely stops existing, not just becoming undefined), returning a boolean indicating success.
  • 📌 Interview term: the real, direct answer to the prompt — verified directly: delete arr[1] on [1, 2, 3] genuinely leaves a real hole at index 1 — the array's .length stays 3, and index 1 genuinely stops existing (confirmed via 1 in arr becoming false) — it does not shift the later elements down, which is exactly what makes it different from splice (covered in this bank's own dedicated slice/splice question), which genuinely DOES shift indices down.
  • 📌 Interview term: delete vs. setting undefined — a precise answer distinguishes delete obj.x (the key genuinely stops existing — "x" in obj becomes false) from obj.x = undefined (the key still genuinely exists, just holding the value undefined"x" in obj stays true) — a real, verifiable distinction most candidates conflate.
  • 📌 Interview term: non-configurable properties — verified directly: delete on a property of a frozen object genuinely returns false silently in sloppy mode (no error, but nothing removed), while the identical call in strict mode genuinely throws a real TypeError.
  • A precise answer names that delete only ever operates on object properties, never on plain variables — verified directly, attempting delete on a declared variable is a genuine no-op, since variables are not object properties in the same sense (this is also why modern linters flag delete on anything but a genuine property access).

Clarifying questions expected:

  • None — this is a definitional/technical question; directly answering the prompt's exact array scenario (hole, not a shift) is the strong signal.

Code / implementation expected: Yes — reproducing the prompt's exact scenario and directly confirming the resulting hole (via .length and in) is the clearest, most convincing demonstration.

deleteobjects
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals interviews. Difficulty: Easy

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every before/after state and boolean result below was actually run in Node.

1. Why This

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal proof: delete leaves a real hole on an array (unlike splice), and behaves differently for keys vs. setting undefined
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 91 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track