ES6 Flashcards
What is a code block? What are some examples of a code block?
A block of code within curly braces
What does block scope mean?
variables and functions are only accessible within the block/function
What is the scope of a variable declared with const or let?
block scope
What is the difference between let and const?
let can be reassigned
Why is it possible to .push() a new value into a const variable that points to an Array?
Is changes the the value, doesn’t reassign the constant
How should you decide on which type of declaration to use?
When you want to reassign, use let
What is destructuring, conceptually?
Extracting multiple values from data stored in objects and arrays and storing them in variables.
What is the syntax for Object destructuring?
let/const { } = name of object
What is the syntax for Array destructuring?
let/const [ ] = name of array
How can you tell the difference between destructuring and creating Object/Array literals?
Left hand side = for object literals, Right hand side = for destructuring
What is the syntax for defining an arrow function?
let something = (x, y) => x + y;
let something = (x, y) => { return x + y; };
numbers.sort((a, b) => a - b);
When an arrow function’s body is left without curly braces, what changes in its functionality?
You need to specify the return statement
How is the value of this determined within an arrow function?
By the surrounding scope (parent)
What are the three states a Promise can be in?
pending, fulfilled, rejected
How do you handle the fulfillment of a Promise?
then()