DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

What's the output?

var x = 5;

(function() {
  console.log(x);
  var x = 10;
  console.log(x);
})();
Enter fullscreen mode Exit fullscreen mode

Output

undefined 10
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 (3)

Collapse
 
retronav profile image
Pranav Karawale

I think the variable becomes out of scope in the IIFE so maybe it returns undefined. Nice experiment!

 
ml318097 profile image
Mehul Lakhanpal

What help do you need?

Collapse
 
ml318097 profile image
Mehul Lakhanpal

Thanks :)