let valueOne = 3;
let valueTwo = "3";
if(valueOne==valueTwo)
{console.log("same")}
else
{console.log("different")}
console.log("valueOne==valueTwo: " + valueOne==valueTwo);
Why is the output:
same
false
It doesn't even print the string valueOne==valueTwo:
.
However, when extra parentheses are added it's outputting the expected results.
console.log("valueOne==valueTwo: " + (valueOne==valueTwo));
Output:
same
valueOne==valueTwo: true
It appears that the ==
operator has lower precedence than concatenation in javascript,
http://www.scriptingmaster.com/javascript/operator-precedence.asp
which is different from Java:
https://introcs.cs.princeton.edu/java/11precedence/
Anyone know the design concern here?
Thanks!