Execution Context – code execution

Execution Context has two phases:

– Creation phase: sets up functions, variables inside of memory
– Execution phase: It runs your code

output:

Called b!
undefined
Hello World!

Basically after the creation phase, it starts executing.

Function as a whole was in memory. So executing it gives us:
Called b!

Then when we tried logging a, a is indeed in memory, but its value is undefined, which was set in the Creation Phase.

So it displays ‘undefined’.

Then we go down to the next line and sees that a is set to ‘Hello World!’.
Then we go down one line further and logs it. This time, a is set to a string, and we display that string.