Professional Documents
Culture Documents
Amar
Lead NodeJs developer and
solution provider.
ES8
New features
Object.values
Object.entries
String.prototype.padStart
String.prototype.padEnd
async/await
Object.getOwnPropertyDescriptors
Object.values
Object.values(NaN); // []
Object.values(function() { }). // []
Object.entries
This method returns an enumerable array of key and value pairs like [key,
Example 1:
console.log(Object.entries(obj));
Output: [['name', 'Amar'], ['email', 'amar@gmail.com']]
Example 2:
for(const [key, value] of Object.entries(obj)){
console.log(`${key}: ${value}`);
}
Output:
name: Amar
email: amar@gmail.com
Example:3
const obj1 = {id:1, name: 'Amar', prices: [23,24,25, '$']};
for(const [key, value] of Object.entries(obj1)) {
console.log(`${key}: ${value}`)
}
Output:
id: 1
name: Amar
prices: 23,24,25,$
String.prototype.padStart
This method allows to padding at the starting of the string multiple times
until it reaches to the given length
For instance
const str = 5;
console.log(str.padStart(5, 0)); // Uncaught TypeError: str.padStart
is not a function
String.prototype.padEnd
This method allows to add padding at the end of the string until it reaches to
the given length. Let’s see the behaviour of this method
Trailing commas or final commas are functional while adding new elements
parameters and properties in Javascript. ECMA 2017 (ES8) allows trailing
commas to function parameter list and function calls. So, Let’s crack how to
use this.
class Formulas {
sum(a,b,) {
return a+b;
}
multiply(a,b,) {
return a*b;
}
}
Usually, trailing commas used to add new property in a new line without
modifying the existing line. But, ES8 supports add trailing commas in
function parameters too. To know more trailing commas then you guys can
refer this link. You can go through plenty of examples given in the link to
understand the main use case of trailing commas in Javascript.
function getAsyncContent() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Hi! How are you ?');
}, 3000);
});
}
function getData(){
getAsyncContent
.then(result => console.log(result))
.catch(error => console.log(error));
}
(async () => {
const result = await getAsyncContent();
console.log(result); // Hi! How are you ? (After 3 seconds)
})();
Object.getOwnPropertyDescriptors
const object1 = {
property1: 42
};
Note: If the writable is false then we can not replace the value of
that key in the object
In case, the purpose of writable, readable and enumerable are not known then
please update in comments then we can publish a separate article for this.
NodeJs Compatibility
All ES8 features started supporting from version 8.2.1. To be more specific
feature support in NodeJs see below.
Object.values — v7.5.0
Object.entries — v7.5.0
String.prototype.padStart — v8.2.1
String.prototype.padEnd — v8.2.1
Trailing commas in parameters — v8.2.1
Async functions — v7.10.1
Object.getOwnPropertyDescriptors— v7.5.0
As we shown these are main features that ECMA introduced in ES8 version.
This is one of the watermark version with its amazing features such as
async/await after ES6. Our main focus on this article is about ES8. That’s the
reason I could not cover much information about trailing commas use cases,
holes in arrays, iterator behaviour with holes in the array. Please mention in
comments if you are really interested to know deep details about trailing
commas then I will publish a separate article on this topic. Our next article on
ES9 will be published soon.
By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about
our privacy practices.
67 1
Jun 30
The Right Way To Intro to using the State Simplicity is not the Solving Duplicate
Develop Your Ethereum Hook in React solution to Software Counting
Dapp is Here: DRIZZLE! Caitlin R
Complexity Jr Medina
Niharika Singh in Neeraj Sangal
HackerNoon.com