Null check gotchas
· ☕ 1 min read
Beware of these null check gotchas.
Consider this code -
1 2 3 4 5 6 7 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.