Recently, I have been experimenting with the typeof operator in relation to the variables I am defining. In my Chrome developer console, I tried a statement that declared several variables like this:
var x, y, z;
Then, I proceeded to assign values to each variable like so:
var x = 7;
var y = 100;
var z = x + y;
Since it involved an arithmetic expression, when I used the typeof operator on each variable, it returned the string 'number'.
Curious about JavaScript quirks, I decided to play around some more and encountered something odd.
I then set each variable to undefined like this:
var x;
When I checked the type using the typeof operator on 'x', the result was unexpected.
typeof (x);
The output still showed as 'number'.
So, my question is: why does the typeof operator keep returning 'number' for an undefined variable in my example above?