es6 Flashcards
What is a code block? What are some examples of a code block?
an area within curly braces with the exception of a for loop. Some examples are functions definitions and for loops.
What does block scope mean?
if it’s inside the code block it stays in the code block.
What is the scope of a variable declared with const or let?
block scoped which means they stay within the code block.
What is the difference between let and const?
let can be reassigned and const cannot be reassigned.
Why is it possible to .push() a new value into a const variable that points to an Array?
you are not re-assigning the array itself, but instead adding to it.
How should you decide on which type of declaration to use?
use const and let the compiler tell you if you are unsure which declaration to use. If it is gonna be reassigned use let if not use const.
What is the syntax for writing a template literal?
backticks and $ and curly braces for substitutions.
What is “string interpolation”?
The substitutions allow you to embed variables and expressions in a string. The JavaScript engine will automatically replace these variables and expressions with their values.
What is destructuring, conceptually?
taking parts of it out and re-assigning them
What is the syntax for Object destructuring?
keyword const or let, curly braces, property name, =, and name of original object
What is the syntax for Array destructuring?
keyword const or let, square bracket, name of element at index, =, name of original array
How can you tell the difference between destructuring and creating Object / Array literals?
which side the equal sign is on the variable name. Left side is destructuring and right side is creating.
What is the syntax for defining an arrow function?
() => with or without curly braces
When an arrow function’s body is left without curly braces, what changes in its functionality?
returns the expressions without curly braces only one expression is returned
What are the three states a Promise can be in?