I recently added a HasValue function to our internal javascript library:
function HasValue(item) {
return (item !== undefined && item !== null);
}
And during the escort with a colleague, we came up with the idea of โโadding another function that would basically be just inverse: perhaps HasNoValue or IsNothing If we finished this, we would get:
function HasNoValue(item) {
return (item === undefined || item === null);
}
function HasValue(item) {
return !HasNoValue(item);
}
However, we are not sure whether it is more readable to have both, or HasValue. Which is more readable / preferred?
A:
if (HasValue(x) && !HasValue(y))
IN:
if (HasValue(x) && HasNoValue(y))
source
share