const let Flashcards
What is a code block? What are some examples of a code block?
code block is within the opening and closing curly brace of a function. function definition, if statements, loops
What does block scope mean?
Variable only accessible within the block. not initialized to any value, not attached to global object.
What is the scope of a variable declared with const or let?
Block scope
What is the difference between let and const?
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.
Why is it possible to .push() a new value into a const variable that points to an Array?
We are not reassigning or changing memory address, but adding to an object or property to the array
How should you decide on which type of declaration to use?
Use const if you don’t intend to modify a variable. Let if value changes, if not sure default to const.