Skip to content

Commit 09e438a

Browse files
JavaScript: Execution Context: GEC, FEC; 2 Phases: Memory Allocation, Code Execution
1 parent c5dff4c commit 09e438a

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

‎JavaScript/ExecutionContext.html‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Execution Context</title>
7+
</head>
8+
<body>
9+
<h1>Execution Context</h1>
10+
11+
<script>
12+
/*
13+
# Execution Context:
14+
- An environment where JS code runs
15+
- Provided by JavaScript Engine
16+
- Types of execution contexts:
17+
- Global Execution Context (GEC)
18+
- Function Execution Context(s) (FEC)
19+
- 2 Phases in which JS execution happens:
20+
- Memory allocation phase
21+
- Code execution phase
22+
23+
- Resources:
24+
- JS visualizer: https://pythontutor.com/visualize.html#mode=edit
25+
26+
# JavaScript Memory:
27+
- Types
28+
- Stack Memory: Primitive values
29+
- Heap Memory: Non-Primitive values
30+
31+
- Primitive vs Non-primitive assignement
32+
- Primitive: Value gets assigned
33+
- Non-primitive: Reference assigned
34+
*/
35+
36+
/* ----------------------------- */
37+
// var num1 = 10
38+
// var num2 = 20
39+
// console.log(num1 + num2)
40+
41+
// Current phase running: CODE EXECUTION
42+
// JS Memory
43+
// GEC
44+
// num1: 10
45+
// num2: 20
46+
47+
/* ----------------------------- */
48+
// var x = 20
49+
// var y = 40
50+
51+
// function sum() {
52+
// var num1 = 50
53+
// var num2 = 100
54+
// console.log(num1 + num2)
55+
// }
56+
57+
// console.log(x + y)
58+
// sum()
59+
60+
61+
// // Current phase running: CODE EXECUTION
62+
// // JS Memory
63+
// // GEC
64+
// x: 20
65+
// y: 40
66+
// // FEC (sum)
67+
// num1: 50
68+
// num2: 100
69+
</script>
70+
</body>
71+
</html>

0 commit comments

Comments
 (0)