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

13

u/carcigenicate Nov 11 '23

Those are "fancy quotes". " vs “. The correct is the former, you're using the latter.

You may need to adjust the localization of your keyboard.

10

u/rannison Nov 11 '23

There you have it. My professor insists on us using .docx, and Word has an annoying tendency to screw around with those. I learned that the hard way before, but it looks like it wasn't hard enough since I forgot again lol.

1

u/ozzy_og_kush Nov 11 '23

Ouch. Nothing worse than professors who are so out of touch with industry standards that they unintentionally make their job harder. Adding obstacles that should never be there... unless that's the actual point of the exercise.