![Question of the Day #17 [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%252Fwwgwlmhr0h3l6o2v0wdp.png&w=3840&q=75)
Question of the Day #17 [Talk::Overflow]
This post explains a quiz originally shared as a LinkedIn poll . 🔹 The Question let count = 0 ; function increment () { count ++ ; var count ; return count ; } console . log ( increment ()); console . log ( count ); Hint: Think about where var declarations end up before any code runs — and what happens when you increment something that doesn't have a value yet. Follow me for JavaScript puzzles and weekly curations of developer talks & insights at Talk::Overflow: https://talkoverflow.substack.com/ 🔹 Solution Correct answer: B) NaN, 0 The first console.log prints NaN . The second prints 0 . 🧠How this works This quiz targets a subtle but dangerous interaction between var hoisting and variable shadowing. When JavaScript parses the increment function, the var count; declaration is hoisted to the top of the function scope — even though it appears after count++ in the source code. This creates a local count variable inside increment , completely separate from the outer let count = 0 . At run
Continue reading on Dev.to JavaScript
Opens in a new tab


