Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Nullish Coalescing Vs Logical OR opreators

console.log(<left-operand> <operator> <right-operand>);

// same behaviour
console.log(undefined || "John");	// "John"
console.log(undefined ?? "John");	// "John"
            
console.log(null || "John");	// "John"
console.log(null ?? "John");	// "John"

// different behaviour
console.log(0 || "John");	// "John"
console.log(0 ?? "John");	// 0
            
console.log("" || "John");	// "John"
console.log("" ?? "John");	// ""

console.log(false || "John");	// "John"
console.log(false ?? "John");	// false
 
PREVIOUS NEXT
Tagged: #Nullish #Coalescing #Vs #Logical #OR #opreators
ADD COMMENT
Topic
Name
9+9 =