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 becomingundefined), 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 index1— the array's.lengthstays3, and index1genuinely stops existing (confirmed via1 in arrbecomingfalse) — it does not shift the later elements down, which is exactly what makes it different fromsplice(covered in this bank's own dedicated slice/splice question), which genuinely DOES shift indices down. - 📌 Interview term:
deletevs. settingundefined— a precise answer distinguishesdelete obj.x(the key genuinely stops existing —"x" in objbecomesfalse) fromobj.x = undefined(the key still genuinely exists, just holding the valueundefined—"x" in objstaystrue) — a real, verifiable distinction most candidates conflate. - 📌 Interview term: non-configurable properties — verified directly:
deleteon a property of a frozen object genuinely returnsfalsesilently in sloppy mode (no error, but nothing removed), while the identical call in strict mode genuinely throws a realTypeError. - A precise answer names that
deleteonly ever operates on object properties, never on plain variables — verified directly, attemptingdeleteon a declared variable is a genuine no-op, since variables are not object properties in the same sense (this is also why modern linters flagdeleteon 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.