News for hackers. Stuff that matters.
Re:Ask HN: Am I the longest-serving programmer – 57 years an... by SonOfLilit on Sunday May 31, 2020 @12:51PM (#23370757)
Implicit string to number conversion is more like C in terms of memory management, in the sense that it's a huge footgun that you will definitely shoot yourself with. I have never seen it prevent errors, only make them worse by hiding them from QA so they can reach production and ruin your weekend.
Re:Ask HN: Am I the longest-serving programmer – 57 years an... by z3t4 on Sunday May 31, 2020 @05:40PM (#23373010)
It's unfortunately in JS that + is used for both string concatenation and number addition. There are however defined rules that anything concatenated with a string becomes a string. And anything used with -/* > < becomes a number. As a beginner in JS I always used -- instead of plus when doing addition. But as I got more experienced I learned what was strings and what was numbers. And if I'm not sure I add an assertion - so that there will be an early error. I also parse all input (user input etc) not even a static strong type system will help you there, you always have to check/parse the input at runtime! JavaScript is strongly typed as in whatever the user inputs it will be converted to a type. JS don't have that many types and usually it becomes a string.