tzvika ofek
tzvika ofek

Reputation: 53

return a conditional statement in javascript

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

Answers (1)

Martin
Martin

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

Related Questions