const let Flashcards

1
Q

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

A

code block is within the opening and closing curly brace of a function. function definition, if statements, loops

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

What does block scope mean?

A

Variable only accessible within the block. not initialized to any value, not attached to global object.

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

const is read-only, identifiers are uppercase, can’t be reassigned. Const can change value of property, but not reassign. Let are mutable, can change value.

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

We are not reassigning or changing memory address, but adding to an object or property to the 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

Use const if you don’t intend to modify a variable. Let if value changes, if not sure default to const.

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