Section 2: Execution Context and Lexical Environments Flashcards
What is a Syntax Parser
- A program - Read the code - Determines what it does Check if grammar is valid
What is a Lexical Environment
Where something sits physically in the code Were code is written is important
In this code, where is sitting “var a” lexically
function hello() {
var a = “hello world”;
}
inside the function
What is an Execution Context
A wrapper to manage the code that is running. The section of code that is running. There are lots of lexical environments. Which one is currently running is managed via execution contexts. It can contain things beyond what you’ve written in your code
What is a Name/Value Pair?
Is a name which maps to a unique value.
In a name/value pair, can we define more than one name/value pair?
Yes
In a name/value pair, a name, can hold more than one value in any given context?
No, just one value
in any particular execution context, a name can only exist and be defined with one value?
Yes
in any particular execution context, a name/value pair, can hold more name/value pairs?
Yes
what is an An Object in JS?
Is a collection of name/value pairs(and that value can be a collection of more name/value pairs).
Whenever code is run in JS, where do we say it´s running?
Inside an execution context
What is the base execution context?
the global execution context It´s accesible everywhere to everything in the code
A global execution context creates what things?
A global object(window) A special variable called this
at the global level, what object and keyword are equal?
the window object, and “this”
When we mean Global in JS we mean, what?
Not inside a function
The execution context is created in how many phases?
2 phases
Name the two phases of an execution context?
1st: Creation phase 2nd: Execution phase
What happens in the Creation phase(execution context) in the global environment
- We set up the global object within memory
- creation of “this” keyword
- An outer environment set to null
- variables are set, with a value of undefined
- functions definitions are set with their entire code
In the creation phase(execution context) the parser recognize what? and sets up what?
were you´ve created variables and functions and sets up memory space for variables and functions
In the creationg phase(execution context) a function how is stored in memory?
its entirety placed into memory, its name and code
What is undefined in JS?
It’s actually a special value that JS has within it internally that means that the variable hasn’t been set
What’s happening here: console.log(a) // it’s undefined var a = 5; console.log(a) // 5
When we declare “a”, it’s placed into memory during the creation phase. So the execution context saw “var a” and set up “a” in memory, and so even though i haven’t set it to a value, the JS engine, already set it to this special value called undefined.
What is happening here:
console.log(a) // a is not declared -> “Uncaught ReferenceError: a is not defined”
That’s because that initial execution context creation, that creation phase, when it went through it didn’t find a “var a” so it never set up the memory space. So when it went to execute this code it said “hey, I don’t have a in memory at all, so it gave you an Uncaught Reference, a is not defined. I don’t have it in memory”
What is the name of the second phase in the execution context?
Execution phase
