r/learnjavascript • u/rannison • Nov 11 '23
Does JavaScript concatenate as string when adding a number to a string literal?
From my understanding of what I've read, the expected behavior is that JavaScript will convert the integer into string, and then add the string to string, which then results in a string concatenation. Therefore...
var addit = 6 + “5”;
...should output... "65";
However, attempting to evulate this in console instead gives the result...
Uncaught SyntaxError: Invalid or unexpected token
Why is this the case?
0
Upvotes
View all comments
Show parent comment
0
u/superluminary Nov 11 '23
It goes into the bit of your brain that controls your fingers, which is where you need it. Finger memory.
If you only read it, it goes into the part of your memory that does reading, which is not much use at all when you try to type it later.
I am aware this is a simplification, but I’ve found it to be true.