DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

What's the output? Hoisting question

var i = 5;
if(true){
  var i = 10;
}
console.log(i);
Enter fullscreen mode Exit fullscreen mode

Thanks for reading 💙

Follow @codedrops.tech for daily posts.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Top comments (4)

Collapse
 
1qk1 profile image
Panagiotis Skarlas • Edited

Bruh this is scope, not hoisting.

(Also the answer is 5)

Collapse
 
ml318097 profile image
Mehul Lakhanpal

It is hoisting too. And the answer is 10

Collapse
 
1qk1 profile image
Panagiotis Skarlas • Edited

Oh wow. There is a reason var is deprecated haha. Sorry my friend, I'm an idiot.

Thread Thread
 
ml318097 profile image
Mehul Lakhanpal

No problem. Everyone was at situation once 😀