Horo-scopes

In JavaScript, scopes define where a variable is available for use. Learn about each type by reading their horo-scopes below.

Global

Variables declared outside all functions or curly braces exist in the global scope. Global variables can be accessed by any line of code in the program. While they're always available, they can also be easily overwritten, which means it's best practice to avoid them.

Local

When a variable is declared inside a function, it is only available for use within that function. In other words, it is locally scoped and cannot be accessed outside the function declaration. Any effort to reference a local variable outside its scope will result in an error.

Block

Block scope is a sub-type of local scope. Variables that live inside curly brackets { } exist in the block scope. These curly brackets can be of loops, conditional statements, or other expression. You are only allowed to access block scope variables from within the curly brackets.