Operator precedence with JavaScript’s ternary operator

Use: h.className = h.className + (h.className ? ‘ error’ : ‘error’) You want the operator to work for h.className. Better be specific about it. Of course, no harm should come from h.className += ‘ error’, but that’s another matter. Also, note that + has precedence over the ternary operator: JavaScript Operator Precedence

Why doesn’t Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||=)

Reason The operators &&= and ||= are not available on Java because for most of the developers these operators are: error-prone useless Example for &&= If Java allowed &&= operator, then that code: bool isOk = true; //becomes false when at least a function returns false isOK &&= f1(); isOK &&= f2(); //we may expect … Read more

Operator precedence with Javascript Ternary operator

h.className = h.className + (h.className ? ‘ error’ : ‘error’) You want the operator to work for h.className, better be specific about it. Of course, no harm should come from h.className += ‘ error’, but that’s another matter. Also, note that + has precedence over the ternary operator: JavaScript Operator Precedence