Study from 5/5/22 Flashcards

1
Q

How would you describe the callstack?

A

Think of it as a stack of books.

First in Last out (FiLo)

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

How would you describe a queue?

A

Think of a grocery store line.

First in First out (FiFo)

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

How would you describe a closure?

A

A function combined with a lexical state.

They require more memory and power than a pure function.

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

Why do we use closures?

A

Data encapsulation - to prevent leaking data or exposing data where it’s not needed.

For ex.
You can have an outer function that contains the state then an inner function that operates on that state.

The inner function has access to the outer function but the outer doesn’t have access to the inner function

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

What’s the difference in scoping with var, let, const?

A

Var : can be reassigned. It’s function scoped.

Let : can be reassigned. It’s block scoped.

Const: cannot be reassigned. Think constant.

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