Skip to content

Commit e9b6fff

Browse files
committed
scope - color bucket analogy
1 parent 3d7e0cc commit e9b6fff

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ Abstract Operations: ToPrimitive, ToString, ToNumber and ToBoolean
1111
## [Abstract Equality Comparison vs Strict Equality Comparison](abstract-equality-vs-strict-equality/README.md)
1212

1313
Abstract Equality Comparison, Strict Equality Comparison, Corner cases of Abstract Equality Comparison.
14+
15+
## [Scope](scope/README.md)
16+
17+
Lexical scope, Closure, Module Patterns

scope/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Scope (Lexical Scope)
2+
3+
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.
4+
5+
JavaScript organizes scopes with functions and blocks.
6+
7+
## Scope - Color Bucket Analogy
8+
9+
<!-- prettier-ignore -->
10+
```js
11+
var 🔴instructor = "Kyle";
12+
13+
function 🔴otherClass() {
14+
var 🔵instructor = "Suzy";
15+
console.log("Welcome!");
16+
}
17+
18+
function 🔴ask() {
19+
var 🟢question = "Why?";
20+
console.log(question);
21+
}
22+
23+
otherClass(); // Welcome!
24+
ask(); // Why?
25+
```

0 commit comments

Comments
 (0)