Const-Let Flashcards
What is a code block? What are some examples of a code block?
a pair of braces ( {…} ) used to group multiple statements together,
ex.
if else, for, do, while, try catch
What does block scope mean?
Declaring a variable inside and outside a block and having different values returned
What is the scope of a variable declared with const or let?
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.
What is the difference between let and const?
const keyword creates a read-only reference to a value.
let keyword starts from the block until the initialization is evaluated
Why is it possible to .push() a new value into a const variable that points to an Array?
because we are not redeclaring the variable we are just adding to the list
How should you decide on which type of declaration to use?
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