Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

The Optional Chaining Operator (?.)

The Optional Chaining Operator returns undefined if an object is null or undefined, rather than throwing an error.

Example

const car = {type:“Fiat”, model:“500”, color:“white”};
let name = car?.name;

The ?.= operator has been supported in all modern browsers since March 2020.

js 6

The &&= Operator

The Logical AND Assignment Operator is used between two values; if the first value is true, the second value is assigned.

Logical AND Assignment Example

let x = 10;
x &&= 5;

The &&= operator has been supported in all modern browsers since September 2020.

js 7

The ||= Operator

The Logical OR Assignment Operator is used between two values; if the first value is false, the second value is assigned.

Logical OR Assignment Example

let x = 10;
x ||= 5;

The ||= operator has been supported in all modern browsers since September 2020.

js 8

The ??= Operator

The Nullish Coalescing Assignment Operator is used between two values; if the first value is null or undefined, the second value is assigned.

Nullish Coalescing Assignment Example

let x;
x ??= 5;

The ??= operator has been supported in all modern browsers since September 2020.

js 9

JavaScript Promise.allSettled()

The Promise.allSettled() method returns a single Promise that resolves after all promises in a given list have settled (either fulfilled or rejected).

Example

// Create a Promise
const myPromise1 = new Promise((resolve, reject) => {
  setTimeout(resolve, 200“King”);
});

// Create another Promise
const myPromise2 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100“Queen”);
});

// Settle All
Promise.allSettled([myPromise1, myPromise2]).then((results) =>
  results.forEach((x) => myDisplay(x.status)),
);

Since March 2020, Promise.allSettled() has been supported in all modern browsers.

js 10