+ 4
Global variable!
How to make a variable global??
3 Answers
+ 4
If I am not wrong you mean," can I use a var that is inside a function and call it outside a function?"
I don't think you can. Because of how javascript, and most languages, scope variables, you can't access variables declared inside a function from outside a function. The variable belongs to the function's scope only, not the global scope.
Reference:
https://stackoverflow.com/questions/39679212/access-a-variable-inside-a-function-which-is-inside-a-function-in-javascript/46925605
Btw, you don't even need that. If you declare it globally(at the beginning of your code), you can access it from a function and change it and also call outside the function.
+ 5
In js, A variable is by default global so you can call them from function:
https://code.sololearn.com/W278oh06sf85
+ 4
Ok, but can I use a var that is inside a function, outside a function??