What are ES2017 - ES8 features?
1. Async/Await
It is a more readable and structured way to handle asynchronous operations, replacing the need for callbacks and chaining promises
2. Object.values()
The Object.values()
method returns an array of the values of an object. It is similar to Object.keys()
, but instead of returning the keys, it returns the actual values.
The order of values in the array is the same as the order of keys in the object.
3. Object.entries()
The Object.entries()
method returns an array of the [key, value] pairs of an object. It is useful when you want to iterate over both the keys and values of an object.
4. String Padding (padStart
and padEnd
)
The padStart()
and padEnd()
methods allow you to pad a string to a specified length with a given string.
const str = "5";
console.log(str.padStart(3, "0")); // "005"
console.log(str.padEnd(3, "0")); // "500"
5. Trailing Commas in Function Parameter Lists and Calls
ES8 allows trailing commas in function parameter lists and function calls, making it easier to modify or add new parameters without editing multiple lines.
6. Shared Memory and Atomics (for Multithreading)
ES8 introduced SharedArrayBuffer and Atomics to allow multithreading in JavaScript, enabling threads to share memory in a safe and coordinated manner.
- SharedArrayBuffer: Provides a way for JavaScript to share memory between threads (Web Workers).
- Atomics: A set of operations to perform safe atomic operations on shared memory, such as reading and writing to
SharedArrayBuffer
.