Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 13, 2021 06:09 am GMT

New Features of JavaScript 2021

Nowadays we should know about some programming languages like C language, C++, CSS, JavaScript, Python, etc. Today we discuss new features of JavaScript that are very useful for programmers/ coders/ developers.

JavaScript is the easiest programming language to learn for beginners. You can learn it from the tutorial by yourself.JavaScript is the front-end programming language.JavaScript gives some new features in 2021 that are very helpful for developers/ coders/ programmers. A few of the features of JavaScript given below:

1. Logical Operators

JavaScript have AND, OR, NOT operators but in new JavaScript updated three new logical operators are as follow:

A. &&= Operator

In the new logical operator if X variable has a specific value, then the variable should be assigned the value of variable Y. That's why we use a console.use(X), now the value of the variable of X is a change from 10 to 15.Let see the example:

    let X = 10;    let Y = 15;    X &&= Y;    console.use(X);    // Now, the output of variable X is 15.

B. ||= Operator

This operator is the opposite of &&= operator. In this case value of variable X is not change. If variable X has the wrong value then variable X and variable Y will be equal. Let see the example:

let X = 10;let Y = 15;X &&= Y;console.use(X);// Now, the output of variable X is 10.

C. ??= Operator

This operator is used to check the value of the variable is NULL or not. Let see the example:

    let X;    let Y = 15;    X ??= 10;    console.use(X);    // Now, the output of variable X is 10.Logic of this operator:    if(X == NULL ||  X == undefined){    X = 10    };

2. replaceAll method using String

We all use replaceAll method using string. The new JavaScript replace method to have a limitation to change the word in a string. It changes only one word at a time.If you want to replace all words at a time you can use the regular expression. Now let see the example:

// with regexlet str = "Hello World!, Hello Their;"console.log(str.replace(/Hello/g, "Hii"));// Output will be "Hii World!, Hii Their;"// without regexlet str = "Hello World!, Hello Their;"console.log(str.replace('Hello', 'Hii'));// output will be"Hii World!, Hello Their;"

3. Using underscores for integers as a separator

Sometimes Integers are used as a data type in a string and array. It's very difficult to find out the perfect number of elements that are in million or billion.

But now in the latest JavaScript, we can easily find the number with the help of underscores(_). We can use underscores as separators in the integer. Let see the example below:

    let number = 1_000_000; // one million    console.log(number);    // output will be 1000000(the number will remain an integer)

4. Promise.any()

Promise.any() is a new function in JavaScript.Promise.any() takes an iterable of Promise objects and, as soon as one of the promises in the iterable fulfills, returns a single promise that resolves with the value from that promise. If no promises in the iterable fulfill, then the returned promise is rejected with an AggregateError, a new subclass of Error that groups together individual errors. This method is opposite from promis.all(). Let see the example:

        const promise1 = Promise.reject(0);        const promise2 = new Promise((resolve) => setTimeout(resolve, 25, 'Even'));        const promise3 = new Promise((resolve) => setTimeout(resolve, 30, 'Odd'));        const promises = [promise1, promise2, promise3];        Promise.any(promises).then((value) => console.log(value));        // output will be "Even" 

Read More


Original Link: https://dev.to/animeshdhanuk/new-features-of-javascript-2021-4p1k

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To