When writing a javascript function to evaluate a multivariate condition, I came across what looks like a parser error in Javascript. Please let me know if I forgot something or if this is appropriate behavior.
In my function, I return the AND
result of several variables, for example:
return // a comment, for kicks a1 && a2 && b1 && b2 && // another comment c1 && c2 && d1 && d2 ;
However, even if all of these variables have an explicit true
value, the function returns undefined
instead of the expected true
.
I tried several return options for this expression, and I found:
- multi-line expression <
- expression on one line - works
- expression for packaging in paretheses - works
- setting a multi-line expression to a variable, then returning the variable - works
See working examples: http://jsfiddle.net/drzaus/38DgX/
Can someone explain why this is happening?
source share