JavaScript Scope and Variable Declaration

🧠 This JavaScript Output Looks TOO Easy… Until You Think Properly Most people answer this confidently. Some answer fast. Many answer wrong let count = 1; function test() { if (!count) { let count = 10; } console.log(count); } test(); No async. No arrays. No operators. Just if, let, and one variable 👀 Still… this one separates guessing from understanding. 🤔 Why this question is interesting Tests scope Tests block vs outer variable Tests truthy / falsy Very common interview-style confusion Looks simple → causes overconfidence 💬 Your Turn Comment your answer like this 👇 Output → Why? → ⚠️ Please don’t run the code. Answer based on understanding. I will post the correct output + a very clear explanation in the evening 📌 Note: This post is meant to learn how JavaScript behaves, not to judge anyone’s skill #JavaScript #FrontendDevelopment #LearnJS #CodingInterview #TechWithVeera #WebDevelopment #100DaysOfCode

  • text

Count undeclared error because count is declared with let which is outside the function which isn't accessible inside the function.

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories