ES7 and ES8 Flashcards
Convert let a = Math.pow(2,5); to es7
let a = 2**5;
Which method within ES7 checks if an element exists in an array?
a. contains()
b. includes()
c. has()
b. includes()
Which of the following method within the ES7 Object prototype can return both keys and values for an object?
a. entries()
b. values()
c. keys()
a. entries(). This function will return an array of two-length arrays that represent the keys and values of an object.
Which keyword tells an async function to wait for a resolved value before continuing to execute code?
a. async
b. await
This keyword will block an async function from continuing until the ‘awaited’ value returns a valid response.
Why do we create modules in modern JavaScript Projects?
To keep each file/module focused and manageable
Classes are a feature which basically replace constructor ______ and _____.
functions and prototypes
What are the two new variable names for es7?
const and let
The spread and rest operators use the same syntax:
…
Is this using a spread or a rest operator?
const oldArray = [1, 2, 3]; const newArray = [...oldArray, 4, 5]; // This now is [1, 2, 3, 4, 5];
spread operator: It pulls elements out of an array or object
The spread operator is extremely useful for cloning arrays and objects. Since both are reference types (and not primitives), copying them safely (i.e. preventing future mutation of the copied original) can be tricky. With the spread operator you have an easy way of creating a (shallow!) clone of the object or array.
Is this using a spread or a rest operator?
const array = [1, 2, 3]; const [a, b] = array; console.log(a); // prints 1 console.log(b); // prints 2 console.log(array); // prints [1, 2, 3]
Rest(destructing operator)
It allows you to easily access the values of arrays or objects and assign them to variables.