javascript new features 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 Y = 15;
X ??= 10;
console.use(X);
// Now, the output of variable X is 10. 

Logic of this operator:

  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:

let str = "Hello World!, Hello Their;"
console.log(str.replace(/Hello/g, "Hii"));
// Output will be "Hii World!, Hii Their;"

// without regex
let 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:

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 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" ```

[New Features of JavaScript 2021](https://cmsinstallation.blogspot.com/2021/05/new-features-of-javascript-2021.html "New Features of JavaScript 2021")

#javascript #jquery #web-development #python

New Features of JavaScript 2021
1.35 GEEK