I recently came up with a code and i am really stuck in my mind…
The code follows as-
var a=1;
if(1){
a=5;
function a(){
console.log("a");
};
}
console.log(a) //This results 5.
where as the another code
var a=1;
if(1){
function a(){
console.log("a");
};
a=5;
}
console.log(a) //This results [Function:a]
I am really confused can anyone help me in the hoisting concept…Thank you
I tried understand what is happening in the code but i really couldn’t get it.
New contributor
Manikanta Sai Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.