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.

Instagram ● Twitter ● Facebook

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

codedrops.tech

Discussion (6)

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 Author

What help do you need?

Collapse
ml318097 profile image
Mehul Lakhanpal Author

Thanks :)