ES6+ Flashcards

1
Q

What new features did ES6 introduce?

A

Things like let, const, arrow functions, for/of, map objects, classes, a few array functions were all introduced.

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

What is the difference between var, let, and const keywords?

A

var - global scope or function/local scoped, can be redeclared and hoisted.

Let - now the preferred compared to var. its block scoped and while it can be updated but not re-declared.

Const - const, once its declared it cannot be redeclared. They are only available in the block they are declared in.

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

Give an example of template literals.

A

string text ${expression} string text

tagFunctionstring text ${expression} string text

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

What’s the difference between a normal function declaration and an arrow function?

A

normal functions created using function declarations or expressions are constructible and callable

the arrow functions are only callable and not constructible

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

Does JS have classes? If so, when were they introduced?

A

parent class/super class

They were introduced with ES6 in 2015.

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

What is object and array destructuring? What is the rest/spread operator?

A

Array Destcturing

JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

rest/spread

instructs the computer to add whatever otherInfo (arguments) supplied by the user into an array.

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

How would you set default values for parameters to a function?

A

Literally just use x=something

function myFunction(x, y) {
if (y === undefined) {
y = 2;
}
}

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

What is the difference between for-of and for-in loops?

A

For in: for( variable in object) {}, loops through the enumerable properties of an object.

For of: for(variable of iterable){}, lets you loop over data structures that are iterable like arrays, strings, maps, node.

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

What’s the benefit of computed property names?

A

It shortens up code and allows for reusability.

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

Explain the async/await keywords. Why is it preferred to use this instead of .then() methods?

A

Async: allows use to write promises based on code as if it was syncrhonous and checks that we aren’t breaking a thread.

Await: waits for a pormise to happen to ensure the promise returns the result, only makes an async block wait.

.then() is not as optimized as await and await is internal code. Also await is a bit less code intensive.

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

What is a generator function? What’s the point of the yield keyword?

A

This is a type of function that produces a result from a yield, after returning the yield the program will maintain the state of the function and resume where it left off.

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

What built-in data structures does JavaScript provide?

A
  1. Objects (object, array, map, set, weakmap, weakset, date, and anything made with the new keyword)
  2. Functions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly