Skip to content
DevMeme
647 of 7435
Senior Dev Unfazed by JavaScript Hoisting Trick
Interviews Post #735, on Oct 13, 2019 in TG

Senior Dev Unfazed by JavaScript Hoisting Trick

Description

A two-part meme comparing a JavaScript interview question to an anime reaction. The top half displays a code snippet in a dark-themed editor. The code reads: '6 var a = 1; 7 function f() { 8 console.log(a); 9 var a = 5; 10 } 11 12 f();'. Below the code, white text says, 'When javascript interviewer tries to trick senior.'. The bottom half of the image features Itachi Uchiha from the anime Naruto, looking calmly dismissive. A subtitle at the very bottom reads, 'Genjutsu of that level doesn't work on me.' The technical joke lies in the JavaScript code's behavior due to 'hoisting.' The declaration 'var a' inside function f() is hoisted to the top of its scope, shadowing the global 'a'. However, the initialization to 5 happens after the console.log, so the output is 'undefined', not 1 or 5. This is a classic 'gotcha' question that a senior developer would recognize immediately, making the interviewer's attempt a 'low-level genjutsu' (illusion) that fails to deceive them

Comments

7
Anonymous ★ Top Pick Using 'var' hoisting as an interview trick in 2024 is like asking a senior architect if they've heard of that hot new framework, jQuery. The only thing it reveals is the age of their question list
  1. Anonymous ★ Top Pick

    Using 'var' hoisting as an interview trick in 2024 is like asking a senior architect if they've heard of that hot new framework, jQuery. The only thing it reveals is the age of their question list

  2. Anonymous

    After two decades you don’t even run the snippet - you can already hear the ‘undefined’ echoing in the interviewer’s stack trace

  3. Anonymous

    After 15 years, I've seen enough hoisting questions to know the real interview red flag is a company still asking them instead of discussing how they handle tech debt from their 2016 jQuery migration that's "almost done."

  4. Anonymous

    Ah yes, the classic 'var hoisting in a closure' interview question - the technical equivalent of asking a seasoned architect if they know what a door is. Senior devs have debugged this exact pattern in production at 3 AM so many times that they can spot hoisting issues in their sleep. It's like trying to use a basic substitution jutsu on someone who's seen every variation of undefined behavior JavaScript has to offer since ES5. Pro tip for interviewers: if you want to actually assess a senior's skills, ask them about their strategy for migrating a legacy codebase from var to const/let without breaking production, not whether they remember that hoisting exists

  5. Anonymous

    Answer: undefined - the local var is hoisted and shadows the global; follow‑up: why isn’t your lint config banning var and shadowing in 2025?

  6. Anonymous

    Nice try - var a inside f() hoists and shadows, so console.log(a) is undefined; that genjutsu worked in 2009 - ask about TDZ, cross‑realm typeof, or the event loop if you want to gauge seniority

  7. Anonymous

    Hoisting tricks? That's 2012 junior bait - seniors evolved past var into full TDZ immunity

Use J and K for navigation