String Concatenation vs Conditional Operator in Java and JavaScript

Java:

System.out.println("client " + authorized ? "authorized" : "unauthorized");

JavaScript:

alert(‘client ‘ + authorized ? ‘authorized’ : ‘unauthorized’);

(Let’s assume that the authorized is a parameter variable)

In Java, if you write code like this, you definitely get a compile time error, since String concatenation gets higher precedence than conditional operator whereas in JavaScript, you don’t get any error although String concatenation has higher precedence just like Java.

Reason for that

[...Continue reading String Concatenation vs Conditional Operator in Java and JavaScript...]