Reputation: 53
i have this kind of method:
function() {
if (condition) {
return true;
}
return false;
}
I thought of returning the condition itself , to make it more clean, and maybe more readable. like this:
function() {
return (condition);
}
is this considered a good practice?
Upvotes: 0
Views: 604
Reputation: 400
If there is no other code than just returning true/false then yes, return just the condition.
function() {
return (condition);
}
Just as you said, it is more readable, less code. I wouldn't even call it good practice, it's more like the first code is a bad practice.
Upvotes: 1