What is the difference between testing and debugging?
What is the difference between testing and debugging?
June 14, 2022
How does 'likely' and 'unlikely' attributes helps us to optimize the execution times in C++20
How does ‘likely’ and ‘unlikely’ attributes helps us to optimize the execution times in C++20
June 28, 2022

June 21, 2022

What is the difference between logical OR Operator(II) and nullish coalescing operator (??) in JS?

The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined and otherwise returns its left-hand side operand.
The logical OR operator (II) is an operator that returns the right-hand side operand if the left operand is any falsy value, not only null or undefined.

const foo= null ?? "string"; 
console.log(foo);
// expected output: "string"

const number @ ?? 42; 
console.log(number); 
// expected output: 0

const number1 @ ?? 12; 
console.log(number1); 
//expected output 0

const number2= 0 || 12; 
console.log(number2); 
//expected output 12 Because || operator is a logical operator
 and boolean value for 0 is false
What is the difference between logical OR Operator(II) and nullish coalescing operator (??) in JS?
This website uses cookies to improve your experience. By using this website you agree to our Data Privacy Statement
Read more