[solved] Are vars defined in Function definitions Global or Local?

I’m doing the Var Scope challenges now and I thought back to this thread and I started to wonder.
e.g.

function minusSeven(num) {
  return num - 7;
}

Is the var num, which is defined in the definition of the function, global or local.
I presume it’s local but who knows right?

It is local to the function. Let’s test it to make sure.

function minusSeven(num) {
  // let's change num's value
  num = num - 7; // num is now 5
  return num;
}

var num = 12;
console.log(minusSeven(num)); // displays 5
console.log(num); // display 12;

The var num = 12; in the global scope is unaffected by the change to num in the local scope of the function.

1 Like

oh that’s a gd idea lol. I didn’t even think of testing it like that.
Hey, did you run that test in a code editor or does the forum have a way to do that?

Holy Shimolies I just tried that and that chrome devTool is awesome.
anyway, yx