JavaScript Scope Flashcards

(8 cards)

1
Q

What is Scope within Programming.

A

Scope defines where variables can be accessed or referenced.

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

What is a block?

A

Code found inside a set of curly braces.

Example an IF or FUNCTION block.

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

Can a function access a global and local variable?

A

Yes a function can call a global variable (Global Scope) and a local variable (Block Scope).

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

Describe Block Scope.

A

Variables that are defined inside a block and only accessible within the block. The variable is known as a local variable.

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

Describe Global namespace.

A

An temp area where global variables are stored allowing them to be accessed from anywhere in the code. The Global namespace is cleared when the code has finished running.

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

What is Scope Pollution

A
  1. Too many names within Global namespace.
  2. Reuse variables within different Scopes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define Tightly Scoping…

A

The practice of defining variables as tightly as possible using block scope.

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

Advantages of Tightly Scoping

A
  1. Code is easier to read as blocks will organise the code into sections.
  2. Easier to keep track of variables.
  3. Easier to maintain due to Modularity.
  4. Save memory as variables are forgotten after the block has completed running.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly