ES6 JavaScript - What You Need To Know
Destructuring assignment Backtick ( ``) Template Strings
let {a, b} = oassigns Object o's aand bproperties to variables a, b Interpolate with ${expression}
let [a, b] = arrassigns first/second items of Array arrto variables aand b `Token token=${[Link]('accessToken')}`
Can be split over multiple lines
Assign defaults with =, e.g. let {max = 5} = options
Destructuring can be performed on function arguments.
function fn({options = {}, flag = true}) { ... }
...(spread operators / rest parameters)
In functions parameters, creates an array of remaining arguments
function classes(...args) { return [Link](' ') }
for .. ofloops
In function arguments, expands array to actual parameters
Works on Iterables, including Array, Map, Setand generators.
[Link](...args)
Does not work with objects.
Similar to [Link], but doesn't modify this
let
Use with destructuring assignment and
for (let [key, value] of map) { ... }
New ArrayMethods
[Link](callback[, thisArg])
let/ const
return the first item which when passed to callback, produces a truthy value
Make variables scoped by block, not function
Use in place of var [Link](callback[, thisArg])
return the index of the first item which when passed to callbackproduces a
constprevents re-assignment, but does not make assigned objects immutable
truthy value
[Link](value[, start = 0[, end = [Link]]])
fills all the elements of an array from a startindex to an endindex
=>arrow functions
[Link](target, start[, end = [Link]])
argument => returned expression
copies the sequence of items within the array to the position starting with target,
thisinside function is equal to thiswhere it was defined
taken from the position starting with start
function() { ... }.bind(this)
returned expression can be a block
x => { [Link]('doubling'); return x*2 }
New Built-in Classes
Use parentheses for more than one argument
Map- Map keys to values. Unlike objects, keys don't have to be strings
(min, x, max) => [Link](min, [Link](x, max))
Set- Store a set, where each stored value is unique
Use parentheses when argument is being destructured
Symbol- Use to make private object/class properties
({x, y}) => [Link](x*x, y*y)
Promise- Manage callbacks for an event which will occur in the future