Possible Duplicate:
What does tilde (~) preceding jQuery object do?
I found a strange !!~
in the code when reading: https://github.com/LearnBoost/mongoose/blob/master/lib/document.js#L678
Document.prototype.isModified = function (path) {
return !!~this.modifiedPaths.indexOf(path);
};
I have read that What is the !! (not not) operator in JavaScript? and How to: The ~ operator?; why did the author use !!~
here?
I tried:
!!~1 // -> true
!!~0 // -> true
!!~-1 // -> false
!!~-2 // -> true
It seems that it only be false
when the number is -1
. Is it right? Why not just check the number is not -1
or >=0
?