Question presented to candidate: "If you write config.retries ??= 3 and config.retries is already 0, does it get overwritten? What if you'd used ||= instead — same answer?"
What a strong answer should cover:
- 📌 Interview term:
??=,||=,&&=— the logical assignment operators, each conditionally assigning the right-hand side to a variable/property based on the CURRENT value, combining a logical check with assignment in one step. - 📌 Interview term: the real, direct answer to the prompt — verified directly:
x ??= valuegenuinely only assigns whenxis currentlynull/undefined— a real, legitimate0genuinely survives??=untouched.x ||= valuegenuinely assigns for ANY falsy value — the identical real0genuinely gets overwritten by||=, a real, sharp, different answer to the prompt's second question. - 📌 Interview term:
&&=— the mirror case:x &&= valuegenuinely only assigns whenxis currently truthy — verified directly, anullvalue genuinely staysnull, since&&=never assigns to something already falsy. - 📌 Interview term: genuine short-circuiting — verified directly with a real call counter: when the condition for assignment is not met, the right-hand side expression is genuinely never evaluated at all — not just its result discarded, the exact same short-circuiting guarantee this bank's own dedicated short-circuit-evaluation question covers for plain
&&/||. - A precise answer names the real, practical use case directly matching the prompt:
config.retries ??= 3is the correct, idiomatic way to supply a default ONLY for a genuinely missing config value, without accidentally clobbering a deliberately-set0,false, or"".
Clarifying questions expected:
- None — this is a definitional/technical question; directly answering both halves of the prompt's own scenario (
??=vs.||=on a real0) is the strong signal.
Code / implementation expected: Yes — the direct side-by-side ??=-vs-||=-on-a-real-0 comparison is the clearest, most convincing demonstration.