I view the code of express, and see this code https://github.com/visionmedia/express/blob/master/lib/application.js#L490
if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this);
what the ~ means before envs
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In case you were wondering why it is used in that situation, it is a shorthand for finding out if
indexOfmethod found something.indexOfreturns -1 when it doesn’t find something, and >= 0 when it does. So when you do ~-1 you get 0 (a falsy value) and when you do it on anything else you get a truthy value.So:
Is a shorter way of saying
If you are wondering how is -1 the NOT of 0, then read here