Variables defined using the var
keyword in App.js in a node application are not put into the global namespace as if you had used var
in a web page (outside of function scope).
What exactly is the scope of the variables defined using var in app.js?
The top scope is the module (i.e. file). Variables cannot go beyond that. Well, there is a hack, but I do not recommend it.
Each file is the highest scope which would be global
Actually you can use
process.env.USER_DEFINED_VAR
for globally accessible variable between files
The scope of a variable declared using var
is local to the function.
Because javascript's only scope is function scope.