Any variable that is declared outside of function or loops are global scope variable.
Variables with global scopes can be used in any part of your code.
Its limitation is that you cant declare multiple variables with same names.
Example :
these global variables have same names and js throws error because of it.
LOCAL SCOPE
Any variable that is declared inside of function or loops are local scope variable.
Variables with local scopes can only be used inside function. using it outside of function will cause an error.
Unlike variable with global scope you can declare local scope variable with same name inside multiple functions or loops and there wont be any errors because in these variables as long as they are declared in different functions they wont know each other therefore there wont be any naming conflicts between them.
Example :
The x variable in this photo is declared twice with same name but because its declared inside of functions which makes it local function it cant be used outside of function which means that it does not make any problems and js does not throw any errors.