Es 6 Cheatsheet
Es 6 Cheatsheet
Cheat Sheet
Constants let vs var
> console.log(val)
New Types // -> Throws ReferenceError
> let val = 3
Symbols, Maps, WeakMaps and Sets > console.log(val) // -> 3
> {
… let cue = 'Luke, I am your father'
> setTimeout(() => {
… console.log(cue)
… console.log(‘delayed’)
… }
… }, 1000)
> 'Luke, I am your father'
> (function () {
> setTimeout(function () { … var cue = 'Luke, I am your father'
… console.log(‘delayed’) … console.log(cue) // 'Luke, I am –
… }.bind(this), 1000) … }())
> console.log(cue) // Reference Error
Object Notation Novelties String Interpolation, Thanks to Template Literals
// Computed properties
> let key = new Date().getTime()
> const name = 'Tiger'
> let obj = { [key]: “value” }
> const age = 13
> obj
> console.log(`My cat is named ${name} and is
> { '1459958882881': 'value' }
${age} years old.`)
> My cat is named Tiger and is 13 years old.
> let [a, b, c, d] = [1, 2, 3, 4]; > let luke = { occupation: 'jedi',
> console.log(a); father: 'anakin' }
> 1 > let {occupation, father} = luke
> b > console.log(occupation, father)
> 2 > jedi anakin
Spread Operator
...Go Destructuring Like a Boss
Generators
They return a objects that implement an iteration protocol. i.e. it has a next() method that returns { value: < some
value>, done: <true or false> }.