I can’t google the ~ operator to find out more about it. Can someone please explain to me in simple words what it is for and how to use it?
Share
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.
It is a bitwise NOT.
Most common use I’ve seen is a double bitwise NOT, for removing the decimal part of a number, e.g:
Why not use
Math.floor? The trivial reason is that it is faster and uses fewer bytes. The more important reason depends on how you want to treat negative numbers. Consider:So, use
Math.floorfor rounding down, use~~for chopping off (not a technical term).