ES6+ Flashcards
What new features did ES6 introduce?
Things like let, const, arrow functions, for/of, map objects, classes, a few array functions were all introduced.
What is the difference between var, let, and const keywords?
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.
Give an example of template literals.
string text ${expression} string text
tagFunctionstring text ${expression} string text
What’s the difference between a normal function declaration and an arrow function?
normal functions created using function declarations or expressions are constructible and callable
the arrow functions are only callable and not constructible
Does JS have classes? If so, when were they introduced?
parent class/super class
They were introduced with ES6 in 2015.
What is object and array destructuring? What is the rest/spread operator?
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 would you set default values for parameters to a function?
Literally just use x=something
function myFunction(x, y) {
if (y === undefined) {
y = 2;
}
}
What is the difference between for-of and for-in loops?
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.
What’s the benefit of computed property names?
It shortens up code and allows for reusability.
Explain the async/await keywords. Why is it preferred to use this instead of .then() methods?
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.
What is a generator function? What’s the point of the yield keyword?
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.
What built-in data structures does JavaScript provide?
- Objects (object, array, map, set, weakmap, weakset, date, and anything made with the new keyword)
- Functions.