I am editing someone’s code and I don’t understand what they are trying to do with this statement. This is at the end of the function.
return !(this.variable == "value")
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.
They’re returning
trueorfalsebased on the opposite of the result of the comparison.It would probably have been clearer to write:
Sometimes you see:
which forces a “truthiness” conversion of the result of the expression to boolean (
trueorfalse). The “!!” is just a pair of individual logical complement (“not”) operators. The first one (on the right) converts the result of the expression to boolean, but the opposite of the “truthiness”. The second therefore flips it back.