Hello Every one.Today i will explain about a complex forgetable concept. In my experience i think its just big things which is related with some javascript topics. I we can understand this topics then we can easily understand about This. So lets start and explore about Hoisting.Variable and function ,those are hoisted in javascript.
Variable Hoisting-
At first you need to understand about variable.Every varibale have some exicutive part.When javascript execution context phase start working , There is first part is , its have a uniqe name with some role and Javascript using this name as memory reference.Then when Completed javasceript exicution first step in this time javascript save this reference name and by default define with 'undefined' variable.
Lets remember again, first step when javascript using only variable name that is called declearation and then javascript by default decleare a value 'undefined'.That is called initialaization.
But have some different with 'var' and 'let'.
when var keyword to using a name variable , javascript decleare it and by default its define 'undefined' variable.When we are using let keyword javascript decleare it , but javascript by default not difine the value "undefuined", Its totally goes to dead gone.Thats why we can not update the value or can not using this like a var keyword variable.
And Const keyword is totally different , const keyword have specific roles.Its need to declation and initialization togetherly or same line. But If we are not using declearation and initialization in same line , its gives a syntext error for const keyword specific roles.So if you want to decleare and initialization any thins , you first need to fix syntext error.
console.log(x)
let x;
"Cannot access 'x' before initialization"
Remember let , const hoisted and create a memory refernce but window object can not accessed let / const variable.
Funtion Hoistng :
Regular function can hoistited in javascript but regular function can not hoisted on javascript.Its just create a memory reference.
Top comments (2)
Thank you so much.
but i have a question , when i was initialized a let or const variable. I can not found this on window object.