0

My first guess is that the following code has the output of 10 and 100. However, after running the code I get undefined and 100 and I don't understand why the function doesn't see the first declaration of x..

var x = 10;
function f() {
   console.log(x);
   var x = 100;
   console.log(x);
}
f();

2
  • The actual function looks like: function f() { var x; console.log(x); x = 100; console.log(x); } Commented Jan 3, 2022 at 9:51
  • Thank you for your explanation. It helped me understand it now. Commented Jan 3, 2022 at 10:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.