Thinkful Web Development Fundamentals
Unit 2, Lesson 2, Project 3
Thinkful Web Development Fundamentals
Unit 2, Lesson 2, Project 3
Thinkful Web Development Fundamentals
Unit 2, Lesson 2, Project 5
Thinkful Web Development Fundamentals
Unit 2, Lesson 3, Project 3
Thinkful Web Development Fundamentals
Unit 2, Lesson 4, Project 2
Thinkful Web Development Fundamentals
Unit 2, Lesson 4, Project 4
Thinkful Web Development Fundamentals
Unit 2, Lesson 4, Project 6
Scope is the set of rules governing where a variable is valid based on the location of its definition.
Scope can be Global or Local. Any variable defined outside a function (or without the use of let
or const
)has a global scope and is accessible from anywhere in the program. A variable defined inside a function has a local scope and is only accessible from the context in which it was defined or blocks/functions nested within that context. This concept of nesting scope is referred to as the Scope Chain. Local scope will over-ride global scope. So, a variable defined with local scope can have the same name as a variable with global scope, but the program will treat them as separate variables. The value contained in the variable can't rise above where it was defined in the scope chain. Once the program rises out of the local scope, the code will look for a definition in the new scope and will keep looking in progressively higher parent scopes until it finds one. If the code
Thinkful Web Development Fundamentals
Unit 2, Lesson 6, Project 2
Thinkful Web Development Fundamentals
Unit 2, Lesson 6, Project 5