If I declare a variable and don't pass it a value it should be undefined
. I'm confused why console logging my undefined variable name
returns 'undefined' (as expected) but returns "string" when I use the typeof
operator.
var name;
console.log(name); // undefined
typeof name; // "string"
This isn't important, just a curiosity. I also tried this with something similar, like:
var nameVar;
typeof nameVar; // "undefined"
console.log(nameVar); // undefined
The only thing I found poking around is that name
might refer to a DOM element and (though this is just a guess) that might make it behave weirdly in this context? As far as I can tell there's no keyword, and if there was, I wouldn't be able to use it as a variable name.