Beware of these null check gotchas.
Consider this code -
const sum = null;
if (sum) {
console.log("valid sum");
}
// nothing printed
The above code shows expected behaviour. Nothing is printed since if(sum) returns false.
Now, try the code below.
if (sum >= 0) {
console.log("valid zero or positive sum");
}
// valid zero or positive sum
It can throw off your calculations by a wide margin.
Strange but true null >= 0.
But, null > 0 and null == 0 both return false.
To work-around the problem always use the comparison directly in if statement or do an explicit Boolean conversion before the comparison.