Define a global variable in a JavaScript function - Stack Overflow
文章推薦指數: 80 %
As the others have said, you can use var at global scope (outside of all functions and modules) to declare a global variable:
javascriptfunctionvariablesscopedeclaration
延伸文章資訊
- 1JavaScript Scope - W3Schools
Global JavaScript Variables. A variable declared outside a function, becomes GLOBAL. A global var...
- 2JavaScript global variable - javatpoint
JavaScript Global Variable. A JavaScript global variable is declared outside the function or decl...
- 3Javascript Global Variable 全域變數與Local Variable 區域變數 ...
Javascript 的變數可以分為Global Variable(全域變數)與Local Variable(區域變數),這兩種變數的差異在於宣告的位置、方式以及調用區域的.
- 4var - JavaScript | MDN - Mozilla
Assigning a value to an undeclared variable implicitly creates it as a global variable (it become...
- 5Global object - MDN Web Docs Glossary: Definitions of Web ...
In JavaScript, there's always a global object defined. In a web browser, when scripts create glob...