3 ms·
Storing the result of a Boolean expression isn't the strange part. Storing it in a well-named variable can make the code a lot easier to read; the name (hopeful
by pdkl95 7y ago
Storing the result of a Boolean expression isn't the strange part. Storing it in a well-named variable can make the code a lot easier to read; the name (hopefully) communicates intent, and it can separate a conditional action into separate steps.
The strange part is testing Boolean value... to return the same value as Boolean constants.
Why wasn't the Boolean result simply returned directly?
var condn = ...;
return condn;
The if statement isn't necessary. Even if you wanted to explicitly return only "true" or "false" - using the if statement to convert truthy and falsy results into true booleans - using double not operators removes q potentially mispredicted branch.
var condn = ...;
return !!condn;
- bberrry 7y agoAh, sorry, I completely failed to realize that was the question being asked. :)