- Adding strings to a given length.
- Method Object.values().
- Method Object.entries().
- Method Object.getOwnPropertyDescriptors().
- Trailing commas in function parameters.
- Asynchronous functions.
- Work with shared memory and atomic operations.
- Adding lines to a given length ES8 introduced two new object methods String- padStart()and padEnd().
const str = 'test'.padStart(10)
const str1 = 'test'.padEnd(10,'*')
console.log(`'${str}'`) //' test'
console.log(`'${str1}'`) //'test******'
- Method Object.values(). This method returns an array containing the values of the object’s own properties. This method also applies to arrays.
const person = { name: 'Fred', age: 87 }
const personValues = Object.values(person)
console.log(personValues) // ['Fred', 87]
- Method Object.entries(). This method returns an array, each element of which is also an array containing, in format [key, value], keys and values of the object’s own properties.
const person = { name: 'Fred', age: 87 }
const personValues = Object.entries(person)
console.log(personValues) // [['name', 'Fred'], ['age', 87]]
- Method Object.getOwnPropertyDescriptors(). This method returns information about all of the object’s own properties.
const person = { name: 'Fred', age: 87 }
const propDescr = Object.getOwnPropertyDescriptors(person)
console.log(propDescr)
- Trailing commas in function parameters. This feature allows you to leave a comma at the end of the list of parameters or arguments, respectively, when declaring and when calling functions.
const doSomething = (
var1,
var2,
) => {
//...
}
doSomething(
'test1',
'test2',
)
- Asynchronous functions. A design has appeared in the ES2017 standard async/await, which can be considered the most important innovation of this version of the language.
Asynchronous functions are a combination of promises and generators; they simplify constructions that previously required a large amount of template code and inconvenient chains of promises to describe. In fact, we are talking about a high-level abstraction over promises.
function doSomethingAsync() {
return new Promise((resolve) => {
setTimeout(() => resolve('I did something'), 3000)
})
}
async function doSomething() {
console.log(await doSomethingAsync())
}
console.log('Before')
doSomething()
console.log('After')