You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Inside the JavaScript Engine](#inside-the-javascript-engine)
6
+
-[Compilation](#compilation)
7
+
-[Interpretation](#interpretation)
8
+
-[Just in Time (JIT) compilation in JavaScript](#just-in-time-jit-compilation-in-javascript)
9
+
-[Call Stack and Memory Heap](#call-stack-and-memory-heap)
10
+
-[Call Stack](#call-stack)
11
+
-[Memory Heap](#memory-heap)
12
+
-[Stack vs Heap](#stack-vs-heap)
13
+
-[References in JavaScript](#references-in-javascript)
14
+
-[Garbage Collection](#garbage-collection)
15
+
-[Execution Context](#execution-context)
16
+
-[Types of Execution Context](#types-of-execution-context)
17
+
-[Execution Stack](#execution-stack)
18
+
-[Creation of Execution Stack](#creation-of-execution-stack)
19
+
-[Lexical Environment](#lexical-environment)
20
+
-[Hoisting](#hoisting)
21
+
-[Hoisting with let/cosnt](#hoisting-with-letcosnt)
22
+
-[Temproal Dead Zone](#temproal-dead-zone)
23
+
1
24
# JavaScript Engine
2
25
3
26
JavaScript engine is a software or a program responsible to run our JavaScript code. Almost every modern day browsers we use have their own JavaScript engine running in the background. Some of the most popular JavaScript engine are -
@@ -33,9 +56,9 @@ Although most people consider JavaScript as an interpreted language, that is no
33
56
34
57
In this approach, whole program gets compiled into machine language at once and then it is executed. Unlike the compiled language like C, where the compilation is done ahead of time (before actual execution of code), with JavaScript, the compilation is done during execution.
35
58
36
-
###Call Stack and Memory Heap
59
+
## Call Stack and Memory Heap
37
60
38
-
####Call Stack
61
+
### Call Stack
39
62
40
63
JavaScript is a single-threaded language i.e. it has only one call stack and it can process one statement at time. The call stack keeps track of functions to be executed. Call Stack follows the **Last in, First Out** principle which means it always process the call on top of the stack at first.
41
64
@@ -82,25 +105,25 @@ The call stack is empty now and the final output would look like this:
82
105
"I am a robot.";
83
106
```
84
107
85
-
####Memory Heap
108
+
### Memory Heap
86
109
87
110
JavaScript stores objects and functions in heap. Unlike stack, JavaScript engine doesn't allocate a fixed memory for these objects. Instead, more spaces will be allocated as needed. This is called the **dynamic memory allocation.**
88
111
89
-
####Stack vs Heap
112
+
### Stack vs Heap
90
113
91
-
##### Stack
114
+
**Stack**
92
115
93
116
- Primitive values and references
94
117
- Size is known at compile time
95
118
- Allocates a fixed amount of memory.
96
119
97
-
#### Heap
120
+
**Heap**
98
121
99
122
- Objects and functions
100
123
- Size is known at run time
101
124
- No size limit per object
102
125
103
-
#### Examples
126
+
**Examples**
104
127
105
128
```js
106
129
constmyProfile= {
@@ -131,7 +154,7 @@ JavaScript not only allocate memory for objects, they also release the memory. O
131
154
132
155
Execution Context is an concept of an environment where JavaScript code is evaluated and executed.
133
156
134
-
####Types of Execution Context
157
+
### Types of Execution Context
135
158
136
159
-**Global Execution Context** : This is the default execution context. It does two thing: **_creates a global object (window object) and sets the value of *this* to global object._**
137
160
@@ -155,7 +178,7 @@ ExecutionContext = {
155
178
}
156
179
```
157
180
158
-
####Lexical Environment
181
+
### Lexical Environment
159
182
160
183
Lexical Environment is a structure that holds identifier-variable mapping. (_identifier refers to name of variables/functions and the variable is reference to actual object including function object and array object_).
161
184
@@ -186,7 +209,7 @@ Each Lexical Environment has three component:
186
209
- Reference to outer environment
187
210
- _this_ binding
188
211
189
-
### Hoisting
212
+
## Hoisting
190
213
191
214
Hoisting is the default behavior of JavaScript where it defines all the declarations at the top of scope before code execution. JavaScript only hoists declarations, not initialization.
192
215
@@ -302,6 +325,6 @@ But the error "cannot access before initialization" means our JS engine knows th
302
325
303
326
_To summarize, variables declared with **let** or **const** are hoisted **without** a default initialization but the variables declared with **var** are hoisted **with** default initialization of undefined._
304
327
305
-
#### Temproal Dead Zone
328
+
### Temproal Dead Zone
306
329
307
330
This is a period during execution where _let/const_ variables are hoisted but not accessible.
0 commit comments