es6-const-let Flashcards

1
Q

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

A

A code block is a block of code surrounded by curly braces ( { } ). An example of a code block is the code surrounded by curly braces after an “if” statement declaration. Another is a “for” loop declaration.

  • The code inside the curly braces of an object is not a code block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does block scope mean?

A

Block scope means that variables declared inside a block is not visible to code outside of the block.

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

Block scope

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

A variable declared with the const keyword can’t be re-assigned. Variables declared with the let keyword are mutable while variables declared with the const keyword are immutable.

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

Because even though the variable is declared with the const keyword, you can still change the value of the array the const variable points to. You can’t reassign the const variable to another array.

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 declaration to use?

A

If you want to change the value(s) of a variable, declare it with the let keyword. If you don’t want the variable to be reassigned to a different value, declare it with the const keyword.

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