ECMAScript é um conjunto de alterações que guiam o uso do JavaScript.
More info here.
# Block scoping
// let
function fn () {
let x = 0
if (true) {
let x = 1
}
}
// const
const a = 1
# Backtick strings
const message = `Hello ${name}`
const str = `hello
world
!!!`
# Promises
// making a promise
new Promise((resolve, reject) => {
if (ok) { resolve(result) }
else { reject(error) }
})
// using a promise
promise
.then((result) => { ··· })
.catch((error) => { ··· })
// promise with finally
promise
.then((result) => { ··· })
.catch((error) => { ··· })
.finally(() => {
// ...
})
// async-await
async function run () {
const something = await getSomething()
const somethingElse = await getSomethingElse(something)
return [something, somethingElse]
}
# Spread Operator
// objects
const obj = {
...objects,
someProp: true
}
// arrays
const arrs = [
...arr1,
...arr2,
'anything else'
]
# Rest Parameter
function fun1(...ars) {
console.log(args.length);
}
# Fat Arrows
// without args
someFunction(() => {
···
})
// with args
anotherFunction('something', (err, data) => {
...
})
// implicit return
numbers.map(n => n * 2)
numbers.map(n => ({
result: n * 2
})
Text