I recently came up with a code and i am really stuck in my mind. The code follows:
var a = 1;
if (1) {
a = 5;
function a() {
console.log("a");
};
}
console.log(a) //This results 5.
Whereas other 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? 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.
3