Search code examples
javascriptreactjsweb

JavaScript question about: What does "?." means after a function?


What does "?." means after a function? As after i

const user = () => { query.fetch(data); // anything here} but we are getting to access it like user?.name... what does ?. means

const user = () => { query.fetch(data); // anything here}


Solution

  • The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called is undefined or null, it returns undefined instead of throwing an error.