es6-const-let Flashcards

1
Q

What is a code block? What are some examples of a code block?

A

a code block is the section that includes actions you want to carry out

you have function code blocks, if statement code blocks, for loop code blocks. they are always places within a set of curly braces

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

What does block scope mean?

A

it’s sort of like a mini world. if you declare a variable within a scope it will only exist within that scope.

scope is the landscape in which things exist

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

What is the scope of a variable declared with const or let?

A

they are both block scoped variables

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

What is the difference between let and const?

A

block scoped variables defined with const are immutable, aka cannot be reassigned. It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned.

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

Why is it possible to .push() a new value into a const variable that points to an Array?

A

the variable const creates is read only, but not it’s properties. arrays have properties known as indexes, thus they can be assigned values.

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

How should you decide on which type of variable declaration to use?

A

const should be used for variable names that don’t get reassigned while let should be used for variable names that do.

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