JavaScript programs may generate unexpected results if a programmer accidentally uses an assignment operator (=
), instead of a comparison operator (==
) in an if statement.
This if
statement returns false
(as expected) because x is not equal to 10:
Addition is about adding numbers.
Concatenation is about adding strings.
In JavaScript both operations use the same +
operator.
Because of this, adding a number as a number will produce a different result from adding a number as a string: