What does this JavaScript code mean?
flag &= ~CONST
Is it append, prepend, intersection or something else?
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.
This will turn off whatever constant represents.
For example, lets look at a hypothetical example of code which would represent the state of a window:
We could represent the “state” of the window by using
windowState = WS_HASBORDER | WS_HASCLOSEBUTTON | ... etcnow, lets say we want to “turn off” one of these states, well, thats what your example code does…
windowState &= ~WS_HASBORDERNow what the above code does, is it gets the compliment [i guess you could call it the inverted bits] of whatever is to its right, WS_HASBORDER.
So.. WS_HASBORDER has one bit turned on, and everything else is turned off. Its compliment has all bits turned on, except for the one bit that was turned off before.
Since I’ve represented the many constants as bytes, i’ll just show you an example [not that javascript doesn’t represent numbers as bytes, nor can you do so]
_ now for an example
So… windowState gets the value 0x1F
windowState &= ~ WS_HASMAXIMIZEBUTTON
..To finish our calculation
Here are your resulting flags:
On:
WS_HASBORDER
WS_HASCLOSEBUTTON
WS_HASMINIMIZEBUTTON
WS_ISMAXIMIZED
Off:
WS_HASMAXIMIZEBUTTON
Hope that helps. Back to procrastinating homework I go! haha.