今日已更新 380 条资讯 | 累计 41154 条内容
关于我们

The same question, answered by a junior and a senior: eight examples

Martin 2026年09月09日 17:50 2 次阅读 来源:Dev.to

Seniority in an interview is not measured by how much you say. Every answer below is correct. Only one of each pair gets you the offer, and the difference is smaller and more learnable than most people expect. When engineers ask what a senior answer sounds like, they usually get told to be more confident, or to talk about impact. That advice is not wrong but it is unusably vague. Here is something more concrete. In pair after pair below, the senior answer differs in the same four ways: it names the mechanism underneath, it points at a specific situation rather than the general case, it volunteers the cost, and it says what it would measure. Nothing else. Once you can see it, you can do it. 1. JavaScript closures What is a closure? Junior answer: A closure is a function that remembers the variables from the scope where it was defined, so it can still use them later even after that function has returned. Senior answer: It is a function together with a reference to the scope it was created in, so the variables it captured stay alive on the heap instead of dying with the call. That is what makes module patterns and hooks work, and it is also the classic memory leak: hold a closure over something large in a long-lived handler and it is never collected. It also explains the loop bug people hit with var, since one shared binding gets captured instead of one per iteration. The follow-up here is almost always the loop bug or the leak. If you volunteered both, you have already answered it. for ( var i = 0 ; i < 3 ; i ++ ) { setTimeout (() => console . log ( i ), 0 ); } // 3, 3, 3 -- one binding of i, shared by all three closures for ( let i = 0 ; i < 3 ; i ++ ) { setTimeout (() => console . log ( i ), 0 ); } // 0, 1, 2 -- let creates a fresh binding per iteration The version of this that gets shown in interviews. Knowing that it prints 3, 3, 3 is table stakes; being able to say why in terms of bindings is the answer. 2. React re-renders How would you fix a slow React page? Ju

本文内容来源于互联网,版权归原作者所有
查看原文