var x
declares the variable x
but doesn’t assign anything to it.
If you did set its value to undefined
, then that would be undefined
:
function x(){}
var x = undefined;
console.log(typeof x) //"undefined"
So what you made in your example is just
var x;
function x(){}
While in my example it becomes
var x;
function x(){}
x = undefined;
5
solved What is difference between hoisting var x = 3 and var x