Jul 29, 2024
Creation Phase (Memory Creation Phase)
undefined
.Example:
n
(value: 2) → Memory allocated, initial value: undefined
.square
→ Memory allocated, function code stored.square2
, square4
) → Memory allocated, initial value: undefined
.Code Execution Phase
n=2
→ undefined
replaced with 2
.square(n)
creates a new execution context.square
num
, ans
), both initialized to undefined
.num
receives the value from n
(which is 2
).ans = num * num
→ Result stored in ans
.n=2
, then ans
becomes 4
upon returningsquare2
gets value 4
.square2
and E2 for square4
.