So, what would happen if you tried to use a number with this "." operator? Would it throw a type error? Or try to coerce it into a string?
And what about other operators that fall into a similar boat? Like using
obj[attr] for both property access and array entry lookup? Should those be separated out as well, to make it more obvious what you're trying to do. (I know that technically array entry lookup is property access, but on a high level, the two actions are done for different purposes, and a similar argument can easily be made to have a different array lookup operator).
(Also, as a minor note, we would need to pick some other operator, as
. already means property access. You wouldn't be able to concatenate two string variables.)
const x = 'hello '
const y = 'world!'
console.log(x . y) // Today this would print undefined, we can't break this behavior.
I'm a little skeptical about how much value this would actually add. I usually don't feel like I get that confused about what the "+" is doing when reading other people's code, it's usually easy to tell from the context. but as I actually think about this more, I do recall an area in my code where I've wanted to concatenate a bunch of items together as a string, some of which were not strings. I had ended up writing it like this:
return '' + a + b + c + d + e
which feels a little icky. Though, I guess an alternative solution would have been to simply coerce the non-string values into strings first.
return String(a) + String(b) + c + String(d) + e