Reputation: 566
I am trying to check if a username
and userId
exists and either a like
or a comment
exists then return something. And I am using two if conditions for this :
if (username && userID) {
if (like || comment) {
return something
}
}
Is there any way to fit bot the conditions into one single statement. Also, here the username is immutable.
Upvotes: 0
Views: 40
Reputation: 1903
Yup!
if (username && userID && (like || comment)) {
// do stuff
}
Upvotes: 2
Reputation: 370729
Just surround both conditions with brackets so you can group them with &&
?
if (
(username && userID) &&
(like || comment)
) {
return something
}
Upvotes: 3