课程: JavaScript: Scope

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

What are global variables?

What are global variables?

- [Narrator] Global variables are any functions, objects, variables that are declared outside of functions. And when we say global, we mean they are accessible throughout your file. And this is a good time to introduce the variable, lifetime. A term you may hear from time to time. The variable lifetime is when the variable is deleted after it has been declared. In the case of global variables, it is available when declared and deleted when the application is closed, in most case when the browser is closed. And for that reason, it is often not recommended to use global variables. Let's say for example you initialize a global variable with user data. This can be a privacy or security issue. As someone could literally pull data from this variable in the browser. Two nuances to global variables. If you don't declare a variable and you assign a value to a variable inside of a function, it automatically becomes globally…

内容