Horizon
One question: What is JavaScript????
Look, you have to understand what is ES2015+
ECMAScript é um conjunto de alterações que guiam o uso do JavaScript.
More info here.
List of some features
# 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
!!!`
List of some features
# 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]
}
List of some features
# Spread Operator
// objects
const obj = {
...objects,
someProp: true
}
// arrays
const arrs = [
...arr1,
...arr2,
'anything else'
]
# Rest Parameter
function fun1(...ars) {
console.log(args.length);
}
List of some features
# Fat Arrows
// without args
someFunction(() => {
···
})
// with args
anotherFunction('something', (err, data) => {
...
})
// implicit return
numbers.map(n => n * 2)
numbers.map(n => ({
result: n * 2
})
Extras
Text
Horizontata - JS e ES6
By Pedro Mello
Horizontata - JS e ES6
- 175