FAQ: Variables - typeof operator

This is a limitation in JavaScript, if we look at the documentation (link) we can see:

there is only number, no distinction between integers and floats. So far I know, JavaScript is the only language I worked in which doesn’t distinguish integer and float.

Albeit we do have parsing tools that can differentiate between the two…



although they return one or the other, not distinguish them as such.

Can Someone Tell Me Whats Wrong With My Code?? I have been trying to fix it for 2 days now

let newVariable = ‘Playing around with typeof.’;

console.log(typeof newVariable)

newVariable = ‘1’

The step instructs us to set the varialbe to 1, not '1'.

thanks You Helped me Soo Much

1 Like

These exercises would be helpful if we used i.e. typeof in a case like situation. I also wonder what to use it for, and the answer is to check the type of value. But if we took a real world coding situation to show an example of when this would be handy it would sink in better. At least in my head.

The language makes promises. It has fashioned typeof to search up the prototype chain until it finds a parent constructor. That parent will be the type, in a way.

typeof 42  =>  'number'

The parent constructor is Number(). JS must have some way to relate this to 'number' but those inner workings are not clear (to me). It may be an internal property:

type: 'number'

Bottom line, forgive the lessons and commit to due diligence at not leaving any questions unanswered to one’s satisfaction. It all traces back to the promise made by the language.