Is it OK to have a function that returns true/nothing instead of true/false?
My examples use JavaScript, but I'm wondering about the general case, not attached to one specific language.
The subjects of my interest:
- It isIs it OK from the practical side?
- Is it OK from the logical side?
I mean, some languages provide too much freedom and personally I don't like it. I think it is better to follow the way how it works in serious languages like C++ and Java, but I never worked with them.
var a = 1;
var b = 2;
function foo() {
if (a === b)
return true;
}
if (!foo())
alert('error');
versus
function foo() {
if (a === b)
return true;
else
return false;
}