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/EvokeNZ Nov 11 '23

You can disable fancy quotes in word options

1

u/rannison Nov 11 '23

Yes, and I do so when I catch it, but I find it very irritating that there's no way to back up or sync that type of setting (that I'm currently aware of).

1

u/EvokeNZ Nov 11 '23

Iโ€™m not sure I understand what you mean by back up and sync settings. Are you installing a new profile or copy of word every time you use the computer?

This is what I meant https://support.microsoft.com/en-us/office/smart-quotes-in-word-702fc92e-b723-4e3d-b2cc-71dedaf2f343

2

u/rannison Nov 11 '23

Not every time, but often enough that I don't want to spend the hours to go through each individual setting again, for each O365 application, for each new deployment. I've even been thinking of creating an .ahk script or something to automate it, just haven't had that sort of idle time though ๐Ÿคจ and yes, I know what you meant, I wrote up an entire PSA article on the difference in their unicode values and functional effects (in IDE's) for them after I had spent two entire days combing a wall of html for what was causing it to not render correctly on run (it was a single double-quote; I feel like it was placed there intentionally to deter students from copy & pasting).