Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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;
like image 602
unsocialcattle Avatar asked Jan 24 '23 18:01

unsocialcattle


1 Answers

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

like image 65
3limin4t0r Avatar answered Jan 27 '23 08:01

3limin4t0r