0 ?? "default";
// 0
false ?? "default";
// false
[] ?? "default"
// []
/** ⚠️ Pay attention. */
null ?? "default";
// "default"
undefined ?? "default";
// "default"
The ??
operator can be translated as: "return the value on the left UNLESS it's null
or undefined
. If the value is null
or undefined
, then use the value on the left of the ??
.
<Avatar img={profilePicUrl ?? placeholder}/>
Top comments (0)