Does anyone know a good way to force javascript to evaluate all operands in a boolean expression?

In particular, what I am tring to do is essentially this:

return isValid(a) && isValid(b) && isValid(c);

while this technically does work, the function is responsible for highlighting invalid areas on the form for user attention. Since the && operator short circuits, it will only ever highlight the first invalid expression, possibly requiring the user to go through several rounds of correcting input data.

Any ideas?

Recommended Answers

All 2 Replies

 var result = isValid(a);
 result = isValid(b) && result;
 return isValid(c) && result;

Thanks Pritaeas, that will work although less eligant than I like.

I guess the ultimate answer to my question, as my far as research has shown anyway, is that there is no way to not short-circuit boolean operations in javascript.

Kind of limiting if you ask me, but eh.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.