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…

parseInt()

parseFloat()

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.

Yea, I didn’t care for how this particular exercise had a lacking of the right context to figure this out on your own. I assumed the hint was written the way it was to avoid just giving the answer, when it was in fact actually the answer :thinking:

Can someone explain a real world situation where ‘foo’ would be used?

Real world? An imaginary example name in a demonstration.

Take for instance this identity function:

const foo = bar => bar
1 Like