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.