Search code examples
reactjsreact-nativeconditional-operator

What is the meaning of " ?? " in conditional operator in React Native?


I have been encountering with this conditional operator,

phone={this.props.projectDetails?.agency?.phone ?? this.props.projectDetails.phone }

I wanted to use Phone number that is given in agency?.phone but at some point we didn’t had phone number in agency so we were using projectDetail's phone so overcome this issue.


Solution

  • it's Nullish coalescing operator and in your case exactly equal to this :

    phone={this.props.projectDetails?.agency?.phone ? this.props.projectDetails.agency.phone : this.props.projectDetails.phone }