JavaScript NaN Confusion: Understanding Global vs Strict Checking

🛑 This JavaScript Output Confuses Almost Everyone (Even Seniors) Looks very simple, right? Most people answer this confidently… and still get it wrong 😄 console.log(isNaN("hello")); console.log(Number.isNaN("hello")); console.log(isNaN(NaN)); console.log(Number.isNaN(NaN)); No loops. No async. Just NaN. Yet… answers in comments will be all over the place 👀 🤔 Why this question is interesting Tests real understanding of NaN Shows difference between global vs strict checking Very common interview question Looks easy → causes overconfidence Everyone comments something 💬 Your Turn Comment your answers like this 👇 Line 1 → Line 2 → Line 3 → Line 4 → ⚠️ Don’t run the code. Answer based on understanding. I will post the correct output + clear explanation in the evening. 📌 This post is to understand JavaScript behavior, not to judge anyone. #JavaScript #LearnJS #FrontendDevelopment #CodingInterview #TechWithVeera #WebDevelopment

  • text

console.log(isNaN("hello")); Line 1 → true isNaN() first converts the value to a number "hello" → Number("hello") → NaN Since it becomes NaN → result is true console.log(Number.isNaN("hello")); Line 2 → false Number.isNaN()does NOT convert "hello" is a string, not NaN So result is false console.log(isNaN(NaN)); Line 3 → true NaN is already NaN isNaN() detects it → true console.log(Number.isNaN(NaN)); Line 4 → true Number.isNaN() checks strictly Value is exactly NaN → true

See more comments

To view or add a comment, sign in

Explore content categories