Why does Javascript only type-cast for string concatenation on strings that are already assigned?

I noticed something strange when messing around with strings and numbers in a Javascript console. Doing this: “$99.9” += 0 causes SyntaxError: Invalid left-hand side in assignment. But if I assign the string to a variable, the behavior is different (and more in line with what we’ve come to expect/accept from Javascript) let str = “$99.9” str += 0 // => “$99.90” I’m familiar with what causes the behavior in the second example (and what causes so many other Javascripty things to happen), but the error in the first example surprised me. What is happening in the first example of

Casting a number to a string in TypeScript

Which is the the best way (if there is one) to cast from number to string in Typescript? var page_number:number = 3; window.location.hash = page_number; In this case the compiler throws the error: …