Global and local scope in JavaScript

When a variable is declared within a function’s curly braces (using let, const or var) that variable has local scope.

Conversely, when a variable is declared outside a function’s curly braces (using let, const or var) that variable has global scope.

So is scope simply a matter of whether or not a variable is declared inside or outside a function’s curly braces?

For example: In the code below, the initialization expression: var i = 0 contained in the for loop has global scope, correct?

var numArray = [];
for (var  i =  0; i  <  3; i++) {
numArray.push(i);
}

Mostly. var can have some counterintutive scoping behavior, but for let and const any curly braces count, so loops have their own scope as well.

Fun fact, you can actually create scope with any old curly braces. Try this code:

{
  let test = "This Is Only A Test!"
  console.log(test)
}

console.log(test)

Thanks
Learning to code is like: Forest has 4 apples. He eats one and gives one to Jenny. Calculate the mass of Earth's nearest Neutron star (show your work).