Learn JavaScript - Scope Cheatsheet
Learn JavaScript - Scope Cheatsheet
Scope
Scope
Scope is a concept that refers to where values and
functions can be accessed. function myFunction() {
Various scopes include:
console.log(statusMessage);
// Uncaught ReferenceError:
statusMessage is not defined
Global Variables
JavaScript variables that are declared outside of blocks
or functions can exist in the global scope, which means // Variable declared globally
they are accessible throughout a program. Variables const color = 'blue';
declared outside of smaller block or function scopes are
accessible inside those smaller scopes.
function printColor() {
Note: It is best practice to keep global variables to a
minimum. console.log(color);
}