2 Respuestas
+ 1
If you declare a variable inside a function, its scope is inside this function making it not reacheable from outside.
If you leave this function and call it again later on, the variable will be redefined.
The only way to keep a local variable for outside of the function use is by using the return statement (or yield..)
If you declare a global variable it can always be accessed as its scope isnt limited.
The reasons you dont make every variable global are: easier to read code and better usage of resources i.e. memory.
0
depends if the var is declared inside or outside of the function.