Concatenate string with ternary operator in javascript [duplicate]

Your first example is parsed this way

alert(('Array has ' + (arrays.length > 0)) ? 'multiple':('single' + ' value'));

given the operator precedence of + is much higher than that of ?:.

Leave a Comment