-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlexical-scoping.js
More file actions
33 lines (20 loc) · 1.31 KB
/
lexical-scoping.js
File metadata and controls
33 lines (20 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//* Lexical Scoping In Javascript
// -> lexical scoping is a convention used in many programing languages that sets the scope of a variable so that it may only be called (referenced) from within the block of code in which it is defined. During runtime, Javascript does these two things parsing and execution. Lexical scoping takes place during the parsing phase of the js engine
//! what is parser
// A parser is a program that is part of the compiler, and parsing is part of the compiling process. Parsing happens during the anlysis stage of compilation.
// In parsing, code is taken from the preprocessor, broken into smaller pieces and analyzed so other software can understand it.
//* typical steps performed by compilers
// ? => lexical analysis => syntax analysis => semartic analysis => IR code generation => optimization => output code generation
//! parser end
// -> the ability of a function scope to access variables from the parent scope is called Lexical scope.
//? the child function is lexically bonded to the parent But the opposite is not true; the variables defined inside a functioncould not be accessed outside that function.
//! in the exapmle
function car() {
var model = "BMW770";
function displayModel() {
console.log(model);
}
return displayModel;
}
var chooseCar = car();
chooseCar();