ES6 Flashcards

1
Q

What three new methods does ES6 introduce for identifying whether a given string contains a substring?

A

includes(), startsWith() and endsWith() // These won’t work with regular expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are tagged template literals?

A

Functions that receive pieces of a template literal as arguments which you can manipulate and return as html.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you easily clone an array using rest parameters?

A

let […clonedArray] = myArray;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For function doSomething () { … } how can you get the name “doSomething” from within or without the function?

A

doSomething.name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you make sure a function was called with the ‘new’ keyword?

A

if (typeof new.target !== ‘undefined’) { // the function was called using new. This is better than checking if this instanceof Person, for example.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Make an arrow function into an immediately invoked function: (value) => {
doSomething(value)
return value;
}

A

Wrap in parens: ((value) => {…})(‘Something’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s a tail call?

A

When a function is called as the last statement in another function the compiler has trouble optimizing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you optimize for tail calls when they are necessary?

A

Don’t require access to variables in the current stack frame (the function can’t be a closure); the function making the tail call has no more work todo after the tail call returns; the result of the tail call is returned as the function value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does Object.is() work?

A

Accepts 2 arguments and returns true if they are the same type and value. Object.is(NaN, NaN); // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does Object.assign() work?

A

Object.assign(receiver, supplier); It takes two objects and adds the properties/values from supplier to receiver. It modifies receiver.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the super() method do? How does it work?

A

‘super’ is a pointer to the current object’s prototype. It’s like saying Object.getPrototypeOf(this). It must be inside a ‘concise’ method to work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a concise method of an object literal?

A

Instead of var person = { getAge: function() { … } we can say var person = { getAge() { … } ,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why send destructured parameters to a function? What does this mean/do?

A
It helps clarify what the function requires: 
function myFunction (name, value, { url, filename, size }  = { } ) { ... } // Note: the parameters are required if you don't set a default
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Add newItem onto the end of array someArray using spread operator

A

[ …someArray, newItem ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly