Javascript ES6+ Flashcards
Emerging javascript concepts.
What is the scope of a variable declared with let? Why is it useful?
The block its used on. It helps data to remain immutable.
What are default parameters?
Values that a parameter will assume if nothing is passed to it.
When to use parentheses after an arrow funtion?
When we want to return an object, such as:
( ) => ({
a,
b
})
What happens to the scope of “this” in an arrow function when its called globally, compared to how a traditional function dealt with it?
An arrow function protects the scope of “this”, unlike traditional functions that, when called globally, pointed this to the global object (the window).
What is Babel?
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.
What are the 4 tasks performed by the spread operator?
- Combine multiple arrays into one.
- Combine multiple objects into one.
- Skip-through array items (ex. [first, …rest])
- 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}
)
}
What is a promise?
Promises are used as proxies to synchronize a result not yet computed by the time a function is called.
What are the two methods a promise return?
.then and .catch
What happens when a promise is rejected due to error?
The process is not stopped, and the rejection must be handled separately.
When we dont need to use {} on imports?
When its target was exported as default.