What is this "?." feature called, in JavaScript?

Viewed 102

Just realized it exists, thanks to VSCode enforcing it...

  • I don't know what it is called;
  • It's not TypeScript.

Usage

let regex = /hot/g;
let phrase = "It's hot, outside.";

// you don't need to worry about null
let matches = phrase.match(regex)?.length;
1 Answers

That feature is called optional chaining. This calls the method when the receiver is neither undefined nor null.

Related