![Question of the Day #22 [Talk::Overflow]](/_next/image?url=https%3A%2F%2Fmedia2.dev.to%2Fdynamic%2Fimage%2Fwidth%3D1000%2Cheight%3D500%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto%2Fhttps%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Farticles%252Fkjbfc84y0k6t5vmzs8qp.png&w=1200&q=75)
Question of the Day #22 [Talk::Overflow]
Why a function declaration after a return statement still shadows your outer variable — and how this "dead code" hoisting trap silently breaks state updates in production JavaScript. This post explains a quiz originally shared as a LinkedIn poll . 🔹 The Question var x = 1 ; function bar () { x = 10 ; console . log ( x ); return ; function x () {} } bar (); console . log ( x ); Hint: Before any code inside a function runs, the engine has already processed all declarations in the function body — including ones that appear after a return statement. Follow me for JavaScript puzzles and weekly curations of developer talks & insights at Talk::Overflow: https://talkoverflow.substack.com/ 🔹 Solution Correct answer: B) 10, 1 The first console.log prints 10 . The second prints 1 . 🧠 How this works This quiz exploits the fact that function declarations are hoisted to the top of their enclosing function scope — even when they appear after a return statement, where they can never be reached at runt
Continue reading on Dev.to JavaScript
Opens in a new tab


