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

Discussion (4)

Collapse
1qk1 profile image
Panagiotis Skarlas • Edited on

Bruh this is scope, not hoisting.

(Also the answer is 5)

Collapse
318097 profile image
Mehul Lakhanpal Author

It is hoisting too. And the answer is 10

Collapse
1qk1 profile image
Panagiotis Skarlas • Edited on

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

Thread Thread
318097 profile image
Mehul Lakhanpal Author

No problem. Everyone was at situation once 😀