DEV Community

loading...

What's the output?

318097 profile image Mehul Lakhanpal Originally published at codedrops.tech ・1 min read
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

Discussion (6)

pic
Editor guide
Collapse
bacloud14 profile image
bacloud14

codedrops is amazing ! good job Mehul

Collapse
318097 profile image
Collapse
bacloud14 profile image
bacloud14

Could you help my website lol

Thread Thread
318097 profile image
Mehul Lakhanpal Author

What help do you need?

Thread Thread
bacloud14 profile image
bacloud14

check my last post here, but that is only if you feel like to, thanks ! if you like you can help with style

Collapse
obnoxiousnerd profile image
Pranav Karawale

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