Scope
Scope refers to the variables you have access to at various levels in your application. The {}
are there to help you define scope in your files. Let's look at two important types of scope: local
and global
.
File Location
We will be working in the following file:
Global JavaScript Variables
A variable declared outside a function, becomes GLOBAL. All scripts and functions on a web page can access it.
Local Scope
Variables defined inside a function cannot be accessed from anywhere outside the function. Take the following example:
Again, the carName
variable is defined and accessible only in the scope of the function.
More on scope
There is a lot more to know on scope, and we will discuss it as we move forward.
Last updated