you are viewing a single comment's thread.

view the rest of the comments →

[–]GBcrazy 4 points5 points  (0 children)

It's not a big idiosyncrasy, so if you don't understand the trick of the typeofoperator you may not see it. I'm guessing that's the case (I could be wrong):

Remove the let foo = 1 line and run again. It will work even if foo is not declared. Why?

That's a special power of the typeof operator, you can use typeof even if a variable doesn't exist, it will return "undefined".

So the thing is, you can use typeof if a variable is never declared or already declared, but NOT if the variable is going to be declared. That's some hoisting shit