ES-6 Flashcards
what is a code block? what are examples of a code block?
chunk of code to define statements to be executed together indicated by curly braces
ex. functions, for loops, conditionals (if statements)
what does block scope mean?
block scope refers to the area within code block
variables exist only within the corresponding block
what is the scope of a variable declared with const or let?
block scope
what is the difference between let and const?
const keyword creates block-scoped variables whose values can’t be reassigned
let - mutable, const- immutable
why is it possible to .push( ) a new value into a const variable that points to an Array?
value of the const variable is mutable
how should you decide on which type of declaration to use?
consider if the variable needs to be reassigned later on within the block scope - if so, let
const - no reassignment
let - reassignment
favor const over let - when you are stuck in a situation where const won’t work, use let
what is destructuring, conceptually?
allows you to unpack values from arrays, or properties from objects, into distinct variables
what is the syntax for Object destructuring? ** { } curly braces for destructuring isn’t considered a code block
const/let keyword, curly braces, variable names within curly brace, assignment operator, variable
what is the syntax for Array destructuring? ** { } curly braces for destructuring isn’t considered a code block
const/let keyword, brackets, variable names, assignment operator, variable
how can you tell the difference between destructuring and creating Object / Array literals?
destructuring, check for variable name at the end
or if there is no variable name following const/let
what is the syntax for writing a template literal?
using back ticks ` `, ${ } for variables
what is “string interpolation?”
ability to substitute part of the string for the values of variables or expressions
what is the syntax for defining an arrow function?
one param - param => expression (for anonymous)
multiple params - (param1, param2) => expression, requires parantheses
multiple statements - require body brackets and return
when an arrow function’s body is left without curly braces, what changes in its functionality?
it will return a value without the return keyword (implicit return)
how is the value of this determined within an arrow function?
the this value is determined by the enclosing context instead of creating its own this context