Section 2: Execution Context and Lexical Environments Flashcards

1
Q

What is a Syntax Parser

A
  • A program - Read the code - Determines what it does Check if grammar is valid
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Lexical Environment

A

Where something sits physically in the code Were code is written is important

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In this code, where is sitting “var a” lexically

function hello() {

var a = “hello world”;

}

A

inside the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an Execution Context

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Name/Value Pair?

A

Is a name which maps to a unique value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a name/value pair, can we define more than one name/value pair?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In a name/value pair, a name, can hold more than one value in any given context?

A

No, just one value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

in any particular execution context, a name can only exist and be defined with one value?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

in any particular execution context, a name/value pair, can hold more name/value pairs?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is an An Object in JS?

A

Is a collection of name/value pairs(and that value can be a collection of more name/value pairs).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Whenever code is run in JS, where do we say it´s running?

A

Inside an execution context

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the base execution context?

A

the global execution context It´s accesible everywhere to everything in the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A global execution context creates what things?

A

A global object(window) A special variable called this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

at the global level, what object and keyword are equal?

A

the window object, and “this”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When we mean Global in JS we mean, what?

A

Not inside a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The execution context is created in how many phases?

A

2 phases

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Name the two phases of an execution context?

A

1st: Creation phase 2nd: Execution phase

18
Q

What happens in the Creation phase(execution context) in the global environment

A
  • 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
19
Q

In the creation phase(execution context) the parser recognize what? and sets up what?

A

were you´ve created variables and functions and sets up memory space for variables and functions

20
Q

In the creationg phase(execution context) a function how is stored in memory?

A

its entirety placed into memory, its name and code

21
Q

What is undefined in JS?

A

It’s actually a special value that JS has within it internally that means that the variable hasn’t been set

22
Q

What’s happening here: console.log(a) // it’s undefined var a = 5; console.log(a) // 5

A

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.

23
Q

What is happening here:

console.log(a) // a is not declared -> “Uncaught ReferenceError: a is not defined”

A

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”

24
Q

What is the name of the second phase in the execution context?

A

Execution phase

25
Q

what happens in the execution phase?

A

In the execution phase we already have all those things set up that we had before, and now it runs your code, the code you’ve written, line by line, interpreting it, converting it, compiling it, executing it on the computer into something the computer can understand.

26
Q

What means single threaded

A

One command is executed at a time JS isn’t the only thing happening in the browser, so when we say JS is single threaded, it may not be under the hood of the browser, but from our perspective as programmers, JS behaves in a single threaded manner.

27
Q

What it means Synchronous execution

A

In the purposes of programming, one at a time. One line of code being executed for synchronous execution at a time and, in the order that it appears.

28
Q

what it means single threaded synchronous execution

A

In JS, only one thing is happening at a time.

29
Q

What is invocation in JS

A

Running or calling a function, in JS by using the parenthesis()

30
Q

what is the execution stack?

A

one execution context on top of the other on top of the other, And whichever one is on top is the one that’s currently running. So any time you execute or invoke a function in JS, a new execution context is created and put on the execution stack

31
Q

How function invocation happens in JS

A

Every function creates a new execution context which runs through the create phase, then the execution phase were it executes the code line by line within the function

32
Q

What are Variable Environments?

A

Were the variables lives, and how they relate to each other in memory.

33
Q

What happens with a variable that it´s created inside a function?

A

Every variable created and settled inside a function, it will live inside that execution context(the function execution context) and it will be different from others functions and the global execution context.

Every variable is attached to the variable environment of their own execution context. It’s the same to say that every execution context has their own variable environment.

34
Q

Every execution context has a reference to its outer environment?

A

Yes

35
Q

What is the outer environment?

And explain what happens when a variables is called in a function, and how this relate to the outer environment

A

The outer environment it’s related to the Lexical environment, it’s, where the function sits lexically (phisically in the code)

When a function searches for a variable, it will look first for the variable in their own variable environment on their own execution context, if it’s not found, it will take a look at the reference to the outer environment , and look at the variable at that point.

36
Q

When the outer reference is created?

A

When a function invocation takes place.

37
Q

How it’s call to the act of searching for a variable in the chain of references to outer environments

A

The scope chain

38
Q

In terms of Scope Chain

What scope means

and

What Chain means

A

Scope means “where a variable is available in your code, and if’s truly the same variable, or a new copy”

Chapin means “those links of outer environments references”

39
Q

Name anoteher way of thinking about “the reference to the outer environment”

A

Who created me?

the outer reference is to the execution context in which the function was created

“la referencia externa es hacia el contexto de ejecución en donde la función fue creada”

40
Q

In ES6 exist new way of declaring a variable, what is it? and what’s the purpose, and when can we access that variable?

A

its “let”

Purpose: allows the JS engine to use what’s called block scoping.

We can access a variable declared with “let” only after we declared the variable,if we called before, we get an error

41
Q

A variable declared with “let”, if we called before its declared, we can´t access it, but it’s already in memory?

A

Yes, its in memory, but the engine just won´t allow to access it.

42
Q

where lives a “let” variable, and what happens if we are using it inside a loop?

A

it lives inside a block, a block is defined by curly braces { }

If we use it inside a loop, we are going to get a different variable in memory each time the loop is running