JavaScript: Scope Flashcards

1
Q

A variable declared in global scope is available to ____________?

A

All functions

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

A variable declared in local scope is only available to ____________?

A

That function

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

Global Scope in Syntax

A

const hello = “Hello”;

function sayHello() {
console.log(hello);
return;
}

const sayHelloAgain = function () {
console.log(hello);
return;
};

sayHello();
sayHelloAgain();

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

Local Scope in Syntax

A

function sayGoodbye() {
const goodbye = “Goodbye”;
console.log(goodbye);
return;
}

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

What is shadowing?

A

Shadowing happens when the same variable is used in the local and global scope.

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

Shadowing in Syntax

A

const shadow = “Hello”;
console.log(shadow);

function sayWhat() {
console.log(shadow);
return;
}

const sayWhatAgain = function () {
const shadow = “Goodbye”;
console.log(shadow);
};

sayGoodbye();
sayWhat();
sayWhatAgain();

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