alert(typeof(y)); //undefined var y; alert(typeof(y)); //undefined var y=5; alert(typeof(y)); //number
If a variable is declared, but without a value, using
var y; alert(typeof(y)); //undefined if (y in window) alert("yes"); //yes
A variable can have a value "undifined".
var x="undefined"; var y; if (typeof(y) == x) alert("yes"); //yes alert(x); //undefined alert(typeof(x)); //string