Deep JavaScript Foundations, v3

Lexical Scope Elevator

Kyle Simpson

Kyle Simpson

You Don't Know JS
Deep JavaScript Foundations, v3

Check out a free preview of the full Deep JavaScript Foundations, v3 course

The "Lexical Scope Elevator" Lesson is part of the full, Deep JavaScript Foundations, v3 course featured in this preview video. Here's what you'd learn in this lesson:

Kyle introduces a metaphor for lexical scope.


Transcript from the "Lexical Scope Elevator" Lesson

>> Kyle: One metaphor that I have used for years that works well for me and maybe will work well for you. This idea of scopes being nested within each other is similar to a building with a big tall elevator in it, okay? Imagine if you went into a building and you were looking for something but you didn't know where it was.

You just knew it was somewhere in the building or probably somewhere in the building. You'd start on the first floor. You just do basically a linear search. Start on the first floor, look for it there. And if you don't find it, take the elevator to the next floor, look for it there.

If you don't find it, do that again and again and again. And eventually you're gonna arrive at the top floor of the building. And you either find it or you don't, but there's nowhere else to go. So conceptually the first floor is our current scope where the reference is, and the top floor is the global scope.

>> Kyle: We'll come back to this metaphor a later time in the course. So just kinda keep that in your head if that works for you, this idea of going one floor up at a time. We don't immediately jump to the global scope, we just go one floor at a time.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now