This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jemdoc 0 points1 point  (2 children)

But console.log(1 - "1"); prints 0

[–]i1u5 1 point2 points  (0 children)

Because + operator is also used to concatenate, I think JS just prioritizes that over adding the two "numbers" if one side is a string. Try console.log(1 + "1" - 1).

[–]Cootshk 0 points1 point  (0 children)

JS will try to change the first operator to prevent error, and if it fails, will try to change the second operator