I am making sense of an old project that was thrown on me on job. Stumbled upon the following piece (given these two variables were declared somewhere before):
someVar = 234 && !anotherVar;
Is it just a mistake or some fancy ninja move?
I am making sense of an old project that was thrown on me on job. Stumbled upon the following piece (given these two variables were declared somewhere before):
someVar = 234 && !anotherVar;
Is it just a mistake or some fancy ninja move?
&& is logical AND
It expects two arguments and returns:
First term that evaluates to false (is false-y).
Last term otherwise (if no term evaluates to false)
Here are some examples:
0 && false 0 (both are false-y, but 0 is the first)
true && > false false (second one is false-y)
true && true true> (both are true-y)
true && 20 20 (both are true-y)
This definition completely conforms to the definition of logical and from the field of mathematics.
Read More @ Good Explanation of & vs &&