es6-const-let-Q&A Flashcards

1
Q

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

A

JavaScript statements can be grouped together in code blocks, inside curly brackets {…}. The purpose of code blocks is to define statements to be executed together.

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

What does block scope mean?

A

Block scoped variables: A block scoped variable means that the variable defined within a block will not be accessible from outside 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

Both the let and the const keyword are ways to declare block scoped variables. There is one big difference though: Variables declared with let can be reassigned. Variables declared with const have to be initialized when declared and can’t 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

You can change the contents of the array but not change the actual value

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 the variable needs to change use let, otherwise use const

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