Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's the inconsistency.

1 + "2" (12) does a string concatenation. 1 - "2" (-1) does math.

That said, whilst JS is loosely typed and won't fall over when you do this, I'd just see it as bad form to find code mixing types to this extent. Just because the language will let you do it, doesn't mean you should actually do it!



To be fair, the + issue is a mistake many other languages have made too. Incredibly, PHP, poster child of bad languages, gets this right and splits + and . (though this may just be because it copied Perl).


It's fine to have a (string) + (string) operator, it's just generally a less than brilliant idea to have a (string) + (arbitrary) operator that does an implicit string conversion.

But all of that's fine compared to PHP's implicit number conversion that ignores trailing characters, presumably so that you can add "3 onions" to "1 kg of bacon" or some such...


(string) + (string) isn't fine either, if only for performance reasons and because an operator should just do one thing.


I always hear this complaint from classical inheritance people, are you a C/Java supremacist?


Have you heard of this language called "Mathematics?"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: