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.
3
Answers
Nullish coalescing operator means If is null or undefined you will render projectDetails.phone prop
In case if we don’t have any else condition , use Nullish coalescing operator (??)
.. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
it’s Nullish coalescing operator and in your case exactly equal to this :