Variable scope, closure Flashcards

1
Q

{
let message = “Hello”; // only visible in this block
alert(message); // returns
}

A

hello

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

{
let message = “Hello”; // only visible in this block
}

alert(message); // returns?

A

Error: message is not defined

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

{
let message = “Hello”;
alert(message);
}

{
let message = “Goodbye”;
alert(message);
}

both return?

A

Hello
Goodbye

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

let message = “Hello”;
alert(message);

let message = “Goodbye”;
alert(message);

A

// Error: variable already declared

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

if (true) {
let phrase = “Hello!”;
alert(phrase); // return?
}

A

Hello

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

if (true) {
let phrase = “Hello!”;
}

alert(phrase); //

A

Error, no such variable!

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

The Lexical Environment object consists of two parts:

A

Environment Record – an object that stores all local variables as its properties (and some other information like the value of this).

A reference to the outer lexical environment, the one associated with the outer code.

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