Reputation: 2708
I am reading "Discover Meteor" at the moment, In chapter 7 is has code:
Posts.allow({
insert: function(userId, doc) {
// only allow posting if you are logged in
return !! userId; ///// <<==== what does "!!" means?
}
});
Thanks
Upvotes: -2
Views: 152
Reputation: 1722
It just likes you change variable type to boolean
!! userId;
// same as
userId ? true:false;
Upvotes: 0
Reputation: 44834
Beautifully summed up by Tom Ritter as
// Maximum Obscurity:
val.enabled = !!userId;
// Partial Obscurity:
val.enabled = (userId != 0) ? true : false;
// And finally, much easier to understand:
val.enabled = (userId != 0);
therefore doing casting to a boolean and then doing double negation
Upvotes: 3
Reputation: 1670
! will turn any positive value, true, or existing variable(such as strings and arrays) into a false, and any negative, undefined, null, or false into a true. !! applies it twice.
In this context it would be returning true if the variable userId exists and is not empty, null, or false.
Upvotes: 1