What new features did JavaScript have you didn’t know since ES6 through ES11?

Tram Ho

Hello friends,

As you may know, after 6 years of seemingly suspended from the ES5 release in 2009, in June 2015, there was an important update of JavaScript that brought a lot of new features. Since that time, every year we have received a new version with a series of new features that are supposed to bring a lot of benefits and efficiency in the developer work. So far, ES12 or ES2021 is about to release new features, along with that ES11 is an old version. That is enough for us to feel that the methods and ways of operation change and upgrade dramatically. So have you used all of those features? Then in this article, we will take turns going through the features before the end of 2020! Let’s go

ES6 (ECMAScript 2015)

1. Arrow functions (=>)

2. Classes

3. Template strings

4. Let and Const

5. Promises

ES7 (ECMAScript 2016)

1. Array.prototype.includes

2. Exponentiation Operator

ES8 (ECMAScript 2017)

1. Object.values ​​() and Object.entries ()

2. String.prototype.padEnd () and String.prototype.padStart ()

3. Async function (async / await)

ES9 (ECMAScript 2018)

1. Asynchronous iteration

2. Rest operator

3. Promise.prototype.finally

ES10 (ECMAScript 2019)

1. Optional Catch Binding

2. Object.fromEntries ()

3. Array.flat ()

4. Array.flatMap ()

5-6. String.trimStart () & String.trimEnd ()

String.trimStart ()

String.trimEnd ()

7. globalThis Object

ES11 (ECMAScript 2020)

1. Nullish coalescing

First mention the nullish coalescing or operator ?? . According to the definition of MDN, ?? is a logical operator that will return the right side if the left side is null or undefined. So you can use it to short-circuit like this.

1. Optional Chaining?

In the past, accessing the object’s keys would fail if the key didn’t exist, or it is better to first check if the key exists or not. But with ES11, you can handle it simply by operator?.

2. Private fields

By prefixing the property or method with #, they will only be accessible from within the class.

3. BigInt

BigInt is a new built-in object introduced in ES11, used to represent integers greater than 2 ^ (53) –1. In Javascript, there is a Number object, but it is limited in a narrow scope, so BigInt was born to solve this problem.

Take a look at Number’s value limit:

In the third example the data is too large, so we can solve it by using BigInt instead.

Conclude

Although it is a conclusion, but there are some more features of ES6 to ES11 that I have not listed all here, please learn more. Since ES7 onwards, the updates are only minor additions, completely different from ES6, so it’s very easy to upgrade knowledge. Please welcome my next article.

Thank you !

Share the news now

Source : Viblo