'What does ?? ternary operator mean using react and javascript? [duplicate]
i have code like below,
const output = (data?.item?.someItem?.count ?? 0) === 0;
what is the value of output in this case what does ?? in above line mean. could someone help me understand this line of code.
I am new to programming. thanks.
Solution 1:[1]
The "optional chaining operator" ?. gets a property of an object, if that exists and the "nullish coalescing operator" ?? acts very similar to the || operator: It returns the first operand if it is NOT null or undefined , otherwise it returns the second one.
The || behaves slightly differently: It will return the seond operand if the first operand is "falsey" (i. e. 0 or false will also trigger the second operand to be returned).
You can find more details here: MDM Web Docs - Operators
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
