Some “cool” ES6 tips you may not have known – Part 2

Tram Ho

Hello everyone , in the first article of the series ” Some cool tips” of ES6 “, I shared a few small tips and have received more or less attention from everyone. Today, I would like to continue with part 2 of this series. Please follow along!

1. Check 1 variable has the value NaN

JavaScript has one thing oddly, NaN is the only value NEVER by itself. So how do we check its true and false?

Don’t worry, ES6 has introduced a new method for solving this problem, Object.is . Let’s see how it works!

2. Calculate with string data type

If suppose you get data returned including numbers and strings, but for some reason you … lazy to not want to waste the effort converting the string to number before performing the calculation, then apply Now “tips” below see stars

3. Check for existence of subString in String

In ES5, to check for the existence of a string in a string, or an item in an array, we often use the indexOf syntax.

But since ES6 version, you can use the includes() to test if a string contains a substring or not. It determines if the string exists in another string or not, the result will be true or false .

or

4. Remove Duplicates Array

In the previous part, I introduced a method to remove duplicate elements in an array, that is, using the syntax ... In addition, there is one more method of ES6 to do this.


Above are some more tips in the series ” Some cool tips” of ES6 “. Hope to help you in work and study.

I would like to end part 2 here. Good bye and see you again!

Share the news now

Source : Viblo