I have been looking at the source code of raphael.js and I see a lot of stuff like !variable && function() (e.g.: !svg.bottom && (svg.bottom = this); )
What does that exactly do? Does it check first and execute only if not true?
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.
Correct. This is (ab)using short-circuit evaluation. A boolean expression is only executed as far as is needed to determine the result. In your example, if
svg.bottomis non-null, then!svg.bottomisfalse, and the result of the&&isfalse, so execution of the right hand side does not happen. It’s basically equivalent toif(!svg.bottom)svg.bottom = this;