Skip to content

Files

Latest commit

e9b6fff · Dec 9, 2024

History

History
25 lines (18 loc) · 682 Bytes

README.md

File metadata and controls

25 lines (18 loc) · 682 Bytes

Scope (Lexical Scope)

Scope: Where to look for things (identifiers). Before JavaScript start running code it first goes through a parsing phase. During this phase it setup scope this helps during the execution phase JavaScript knows where to look for them.

JavaScript organizes scopes with functions and blocks.

Scope - Color Bucket Analogy

var 🔴instructor = "Kyle";

function 🔴otherClass() {
  var 🔵instructor = "Suzy";
  console.log("Welcome!");
}

function 🔴ask() {
  var 🟢question = "Why?";
  console.log(question);
}

otherClass();                           // Welcome!
ask();                                  // Why?