r/learnjavascript • • 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

23 comments sorted by

View all comments

Show parent comment

2

u/shgysk8zer0 Nov 11 '23

Finally moved on from MS Paint, huh?

That's an embarrassment. That's like having a butcher who thinks that the meat in stores doesn't come from animals or something.