Because of the compiler, even if you initiate a var down below the code, the compiler send it to the top, just like var x;
, so it first initiate as undefined "x" before running console.log, that's why is such a good practice to initate all vars you're going to use first thing in the function, so these mistakes won't happen.