The syntax obtains two question marks which is ‘??’. This operator extracts multiple variables with the first approach fetching the first operand which is not equal to ‘null’ or ‘undefined’.
On the other hand ‘||’ OR operator retrieves all operands starting from the left and and stops at the first one that is ‘truthy’. Anything that is not considered ‘falsy’ can be tagged as a truthy operand. Examples of falsy operands include ‘0’, ‘false’, ‘null’, ‘undefined’, ‘NaN’ or even an `empty` string.
false ?? "value"
// false
undefined ?? "value"
// "value"
null ?? "value"
// "value"
NaN ?? "value"
// NaN
/** compared to || **/
false || "value"
// "value"
undefined || "value"
// "value"
null || "value"
// "value"
NaN || "value"
// "value"
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our ReactJS Expertise.