Const-Let Flashcards

1
Q

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

A

a pair of braces ( {…} ) used to group multiple statements together,
ex.
if else, for, do, while, try catch

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

What does block scope mean?

A

Declaring a variable inside and outside a block and having different values returned

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

const keyword are blocked-scope and cannot be redeclared
let keyword are block-scoped, are not initialized to any value, and are not attached to the global object.

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 keyword creates a read-only reference to a value.
let keyword starts from the block until the initialization is evaluated

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 we are not redeclaring the variable we are just adding to the list

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 var if you want to reassign the value outside of a block
use let if you want to keep the same value outside block but inside block a different value
use const if you want to keep an immutable variable but can still change objects and array naturally

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