Javascript ES6+ Flashcards

Emerging javascript concepts.

1
Q

What is the scope of a variable declared with let? Why is it useful?

A

The block its used on. It helps data to remain immutable.

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

What are default parameters?

A

Values that a parameter will assume if nothing is passed to it.

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

When to use parentheses after an arrow funtion?

A

When we want to return an object, such as:

( ) => ({
a,
b
})

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

What happens to the scope of “this” in an arrow function when its called globally, compared to how a traditional function dealt with it?

A

An arrow function protects the scope of “this”, unlike traditional functions that, when called globally, pointed this to the global object (the window).

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

What is Babel?

A

It is an ES transpiler that converts new features into old code that can be executed in most browsers. It also gives javascript SOURCE CODE that belong to your project and won’t run in the browser.

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

What are the 4 tasks performed by the spread operator?

A
  1. Combine multiple arrays into one.
  2. Combine multiple objects into one.
  3. Skip-through array items (ex. [first, …rest])
  4. Collect arguments as arrays with dynamic positioning, ex.
function directions(...args){
   var [start, ...remaining] = args
   var [finish, ...stops] = remaining.reverse()

console.log(drive through ${stops.length} stops);
console.log(start in ${start})
console.log(destination is ${finish})
}

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

What is a promise?

A

Promises are used as proxies to synchronize a result not yet computed by the time a function is called.

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

What are the two methods a promise return?

A

.then and .catch

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

What happens when a promise is rejected due to error?

A

The process is not stopped, and the rejection must be handled separately.

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

When we dont need to use {} on imports?

A

When its target was exported as default.

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