do functional declaration are hoisted before the variable declaration?

60 views Asked by At

If functional declarations are hoisted before the variable declaration .In that case ,Why I am getting the functional definition instead of undefined.

function a(){}
var a;
console.log(a); // ƒ a(){}

I am expecting that the variable declaration will override the functional declaration and become undefined

1

There are 1 answers

1
Asad Gulzar On

Since you're not assigning a value to a variable and in hoisting JS place an undefined value to a variable. undefined does not override any value, that's why you're getting a function.

function a(){}
var a=1;
console.log(a); // result will be 1