Execution Context Flashcards

1
Q

JavaScript code is evaluated as 1 of the following 3 environments.

A
  1. ) Global code
  2. ) Function code
  3. ) Eval code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When running a function in JavaScript we create a new …

A

Execution Context

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

Is there a limit to function execution contexts?

A

Technically no, depending on the host machine’s resources.

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

How many global execution contexts can there be?

A

Only ever one.

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

A new execution context creates a new …

A

Scope

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

The JavaScript interpreter in a browser is implemented as a … thread

A

single

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

How many things can happen at a time in a single-threaded environment?

A

One

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

What type of data structure is the Execution (call) Stack?

A

A LIFO (last in - first out) data structure

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

When a browser first loads a script, we enter the … context

A

Global execution context

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

What happens when a context has finished executing?

A

The context is popped off the stack and control returns to the context below it until the global context is reached again.

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

Name at least 3 key points about the execution stack.

A
  1. ) The execution stack is single-threaded
  2. ) The execution stack follows synchronous execution
  3. ) There is only ever 1 global context
  4. ) There are technically infinite function contexts
  5. ) Each function call creates a new execution context
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

There are 2 phases / stages to every call to an execution context. They are?

A
  1. ) Creation Stage

2. ) Activation / Code Execution Stage

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

What happens in the Creation Stage of a call to a new execution context?

A
  1. ) It creates a scope chain
  2. ) It creates an activation object (variables, functions, objects)
  3. ) It determines the value of ‘this’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens in the Activation Stage of a call to a new execution context?

A

Assign values, references to functions and interpret / execute code.

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

If an execution context was to be represented visually as an object, what would it look like?

A

It would have a scopeChain property, a variableObject property and a this property.

Each of these properties would have a value of an object.

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

When is the executionContentObject created?

A

When the function is invoked, but before the function has been executed.

17
Q

In what stage is the executionContextObject created?

A

in the Creation Stage

18
Q

Why can we access a function before we have declared it in the code (e.g. top to bottom)

A

Because in the Creation Stage the executionContextObject has been created and a variableObject contains a pointer to the function in memory

19
Q

Why is a variable undefined but does not call an error when referred to?

A

Because the variableObject contains an identifier for the variable with the value of undefined, even if a value is not assigned until the Execution Stage

20
Q

In the Creation Stage, in which order are function and variable identifiers installed?

A
  1. ) Function

2. ) Variable

21
Q

If a property name exists on the variableObject, what happens when it is declared a second time?

A

We skip the subsequent declaration.