I saw another post with the same question and it seemed to have differing explanations. Online resources also seem to have conflicting explanations, unless I am misunderstanding something.
MDN says:
"The scope of a variable declared with var is one of the following curly-brace-enclosed syntaxes that most closely contains the var statement:
Function body
Static initialization block
Or if none of the above applies:
The current module, for code running in module mode
The global scope, for code running in script mode."
My interpretation of this is that the answer to my question would be local scope - local to the function.
w3schools on the other hand says:
"Variables declared with the var keyword can NOT have block scope.
Variables declared inside a { } block can be accessed from outside the block."
If my understanding that function scope is an example of block scope, then this tells me that variables declared inside of a function (which is a block) cannot have block scope - and thus has global scope.
freeCodeCamp says:
"Variables which are declared without the let or const keywords are automatically created in the global scope"
Which also suggests to me that variables declared inside of a function with the var keyword have global scope.
So I am confused as to what the answer is, does a variable declared with the var keyword inside of a function (in the context of JavaScript) have global scope or local scope (local to the function)?
I am sure there is something I am misunderstanding - perhaps a misuse of terminology. Thank you in advance.