I was able to omit the else return false
for this React lifecycle method and still have it work as desired, returning false for odd numbers (value
increments by 1 from 0 -- see freeCodeCamp challenge for the rest of the code), but I'm not clear on why it works this way.
shouldComponentUpdate(nextProps, nextState) {
console.log('Should I update?');
if (nextProps.value % 2 == 0) return true;
}
Since shouldComponentUpdate
defaults to true per React docs, I thought it might still return true even for odd values. I guess the default only applies when there is no condition specified whatsoever.
If an if condition that returns true isn't met and no other conditions are provided, does JavaScript always return false?