Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question Mark in Variable Name

In React custom hook we are returning ordernumber in the below way what does question mark after the variable receipt?.order?.id means in react

export const useTest = props => {
  ...
  return {
    orderTestNumber: receipt?.test?.id
  };
}
like image 427
Arav Avatar asked Mar 02 '23 03:03

Arav


1 Answers

its called Optional chaining (?.)

The optional chaining operator provides a way to simplify accessing values through connected objects when it's possible that a reference or function may be undefined or null.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

like image 182
Jay Avatar answered Mar 05 '23 18:03

Jay