What I know : If variables are initialized without declaration,then it is automatically initialized.
Hoisting in JavaScript only raises the declaration to the top and not the initialization.
What I tried on Google Chrome Console:
console.log(num);
Result:
Uncaught ReferenceError: num is not defined
at <anonymous>:1:13
Cause: Since hum isn't declared or initialized
num = 9; console.log(num);
Result: 9
Cause: Due to initialization, it is also declared and num gets its value ie 9
console.log(hum); hum = 8;
Result:
VM519:1 Uncaught ReferenceError: hum is not defined
at <anonymous>:1:13
What I am not able to understand:
since I have initialized hum
to 8
,it will also get declared and by hoisting in JS,the declaration of hum
is hoisted and I should be getting undifined
as result. Why isn't it happening?