78

Here's something simple to check if user is in moderator. But I want to check if user is not in moderator.

if err && user in moderators
  return

Intuitively it would be like this

if err && user isnt in moderators
  return

But obviously this doesn't work. What's the best way to do it?

2 Answers 2

118

isnt is the opposite of is, which is the triple equals sign. Just negate the in:

if err and user not in moderators
  return

or, using postfix if:

return if err and user not in moderators
Sign up to request clarification or add additional context in comments.

2 Comments

Ohh yeah things make so much more sense now.
You can also use if in postfix form to tidy things up even further: return if err and user not in moderators
13

In CoffeeScript, NOT can be denoted as ! or not

if err && !(user in moderators)

if err && user not in moderators

would both work.

4 Comments

While this may be true, Coffeescript isn't a superset of JavaScript, so not all JavaScript is valid CoffeeScript.
True. But in this case I think it's fine (should I reword it?)
I'd remove the JavaScript part. Also, not and ! are equivalent in CoffeeScript.
Mmk--I don't use coffee script anyway :3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.