跪拜 Guibai
← All articles
Frontend · JavaScript · Interview

10 Popular Front-End Interview Answers Ran Against Real Code: 6 Are Flat Wrong

By kyriewen ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Candidates who recite these answers will fold on the second follow-up question, and production code built on the wrong units or limits will misbehave. The gap between memorized numbers and measured behavior is exactly what interviewers probe with boundary questions.

Summary

The most circulated front-end interview answers fall apart when executed. localStorage's quoted 5MB limit is actually 5,222,400 characters (UTF-16 code units), so ASCII content stores about 10MB. The 20-cookie-per-domain figure is IE6's limit; Chromium hard-codes 180 and silently evicts the oldest. GET URL length is not constrained by HTTP at all — Chrome sent a 1MB URL and got a 200 response; 2048 is an IE relic.

Promise.all does not cancel sibling requests when one rejects; the others finish their HTTP calls. Object.assign is always a shallow copy, and JSON-based deep copy drops undefined, turns Date into a string, and throws on circular references. The claim that "let is not hoisted" is contradicted by the error "Cannot access 'x' before initialization" — the binding exists, it's just in the temporal dead zone. Even the data-type count is stale: six primitives predates bigint, so the correct total is seven primitives plus object.

The failures cluster into three causes: IE-era facts copied without their qualifiers, answers written without ever running the code, and spec phrases like "5 MiB per origin" degraded into "5MB" in retransmission. All tests ran on Node 24.14.1 and local Chrome, with sources archived and scripts reproducible.

Takeaways
— localStorage quota is 5,222,400 UTF-16 characters per origin, not 5MB; ASCII content takes about 10MB.
— Chrome's cookie cap is 180 per domain (kDomainMaxCookies), RFC 6265 requires 50; the 20-cookie answer is from IE6.
— let and const do hoist; accessing them before initialization throws "Cannot access before initialization", which proves the binding exists.
— Promise.all rejects on first failure but does not cancel or terminate the other requests; use AbortController for actual cancellation.
— HTTP has no predefined request-line length limit; Chrome refuses URLs over about 2MB, while servers like Nginx and Python's test server have their own lower caps.
— Object.assign copies property references only, so it is always a shallow copy; nested objects mutate in both source and target.
— JSON.parse(JSON.stringify()) loses undefined, NaN, Infinity, Date (becomes string), RegExp, Map, Set, and throws on circular references.
— Current JavaScript data types: 7 primitives (number, string, boolean, undefined, null, symbol, bigint) plus object, for 8 total.
— const locks the binding between name and value, not the value itself; object properties remain mutable unless Object.freeze() is used.
— Nested setTimeout beyond 5 levels is throttled to a 4ms minimum per the HTML spec; measured delays were [0,0,0,0,0,0,5,5].
— All experiment numbers are version-specific (Node 24.14.1, Chrome); the method of running and verifying against docs is what generalizes.
Conclusions

The three failure modes — fossilized IE facts, code never executed, and qualifiers dropped in retransmission — explain why question banks drift so far from reality.

An interviewer's second-round question probes the boundary of an answer; reciting a conclusion without its conditions is what separates candidates who ran code from those who copied text.

Spec language like "5 MiB per origin" and "IE6 or lower" contains the exact qualifiers that later retellings strip away, making the original document the only reliable check.

Concepts & terms
Temporal Dead Zone (TDZ)
The region before a let or const declaration where the variable binding exists but is not yet initialized; accessing it throws "Cannot access before initialization".
structuredClone()
A built-in function in browsers and Node 18+ that performs deep cloning of structured types, handling Date, Map, Set, RegExp, and circular references correctly unlike JSON.parse(JSON.stringify()).
kDomainMaxCookies
A Chromium source constant set to 180, the maximum number of cookies a single domain can store; exceeding it silently evicts the oldest cookies.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗