es6-const-let Flashcards

1
Q

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

A
denoted by curly braces... examples include if statements, CSS rulesets, functions, loops
if ( ) { //code block//} ;
.ruleset {// code block//}
function ( ) {//code block// }
for ( ) {//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

the variable defined within a block will not be accessible from outside the block- only accessible within that 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, so depending on what point you are referencing it

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

let variables can be updated but not re-declared; const variables can neither be updated nor re-declared

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

This happens because your constant is actually storing a reference to the array, so not changing the const but changing its reference

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

Use let when you know that the value of a variable will change. Use const for every other variable.

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