FizzBuzz "typeof input !== 'number'", theory question

Hey there! This is my first question on this forum. I hope this wasn’t asked previously. Here goes…

During the ‘Control Flow’ module, Exercise 3 named ‘FizzBuzz’ contains in it’s first ‘If statement’ this code:

=> If (typeof input !== ‘number’) return NaN;

My question is, why does ‘typeof input’ not equal “‘number’”?
Why can’t it not equal NaN?

Thanks in advance for your help! :v:

Hi! Are you asking why it can’t look something like this?

if (typeof input === 'NaN') return NaN;

The typeof operator returns one of only eight values, for example 'number' or 'boolean'. It never returns 'NaN'. NaN is not one of the types in JavaScript, but number is, so we use typeof to check if the input to the function is a number, and if not, we return NaN to indicate that we received something that is Not a Number.

I’m not sure if I answered your question!

1 Like

That was so much help thank you for the MDN links! I’m so reading all that. :sweat_smile: