ES6 Cool Features Flashcards
What is used when you don’t want to reassign the variable?
Const
What is used when we want to reassign a variable
Let
What is an old way to declare variable in javaScript and it’s now the weakest keyword to define a variable
Var
What are the differences between Var, Let and Const
- The main difference is in the visibility or accessibility in some areas of code, ie. scope
- When you declare a variable in a function it is visible only within that function, you can’t access it outside.
- Var variables have function scope, while let and const have block scope.
- With let we avoid overwriting variables in the outer scope
- Another potential issue with var is that it can be referenced before it’s assigned
What allows us to initialize functions with default values?
Default parameters
(These values are used when an argument is either omitted or undefined)
What as the name suggests can be included by using the three dots syntax and must be declared at the end of the parameters list?
Rest Parameter
What is usually used because of it’s shorter syntax, compared to traditional functions.
Arrow Functions
What is one of the benefit of using a normal function over an arrow function when using the this keyword?
- When we use a normal function as an object method in the function’s body we can use the this keyword to refer to the object itself.
What has a concise syntax and makes it ideal to use with array processing and accept callback functions, such as sort( ), map( ), and reduce( ) which changes seemingly complex processes into simpler code?
Arrow functions
In ES6 what operator permits the extraction of values from either objects or arrays into distinct variables?
Destructuring
What is denoted by three dots “…” and can be used to “unpack” elements of objects, arrays and strings?
Spread Operator
When the spread operator is applied on objects, it is usually used to combine objects by…
copying the properties of an existing object into another one
What happens when the Spread operator is applied to a string?
It spreads out each individual character of the string into individual characters
When applied on arrays, what can also be used to copy all the elements from an array into another, spreading them out in a specified position?
Spread opearator
Can a Spread operator be used to concatenate two arrays?
Yes