
My Friend Failed an Interview at a Top Company Because of One JavaScript Question: this
My Friend Failed a Top Tech Interview Because of One JavaScript Question: this Recently a friend of mine failed an interview at a top tech company. The interviewer didn't ask about algorithms. Not about system design. Just one topic: The this keyword in JavaScript. At first glance the questions looked simple. But they were designed to reveal whether the candidate truly understands runtime binding in JavaScript. Let's walk through the same interview questions. The Golden Rule of this Before looking at the questions, remember this rule: this is determined by how a function is called, not where it is defined. This single rule explains most this bugs in JavaScript. Interview Question 1 — Object Method vs Unbound Function const module = { x : 42 , getX () { return this . x ; }, }; const unboundGetX = module . getX ; console . log ( unboundGetX ()); What many developers answer 42 Actual result undefined Why? When we write: const unboundGetX = module . getX ; we extract the function from the
Continue reading on Dev.to JavaScript
Opens in a new tab




