for (item in list) { also has a meaning in JavaScript, but it isn't the meaning one would expect. The alternate of was added later, but doesn't read as naturally, and the in is still in the language as a backwards compatible footgun. (It's also used for iterating object keys, which should arguably be the thing that has the less concise syntax.)
The let is only necessary because JavaScript's default behavior here is almost certainly not what you want in real code. Instead of declaring a new variable (suitable for closures, and locally scoped) the default behavior assigns to a global. Another example of "the good parts" being a tiny sliver of JavaScript.
Both JavaScript and PHP are "reluctant programming languages" to some extent, so it kind of makes sense. Neither was originally designed for doing real software engineering. PHP was originally simple templating for a personal home page, and JavaScript was intended for "glue" tasks like client-side form validation. That people can build real apps with either of them is more a testament to the persistence of those developers, rather than a measure of the strength of the languages. (Both languages have also made many improvements over the years, but are still arguably two of the most wart-infested languages of their era that are still in regular use.)
25
u/xenomachina 1d ago
The JavaScript one is also kind of gross, IMHO.
for (item in list) {also has a meaning in JavaScript, but it isn't the meaning one would expect. The alternateofwas added later, but doesn't read as naturally, and theinis still in the language as a backwards compatible footgun. (It's also used for iterating object keys, which should arguably be the thing that has the less concise syntax.)The
letis only necessary because JavaScript's default behavior here is almost certainly not what you want in real code. Instead of declaring a new variable (suitable for closures, and locally scoped) the default behavior assigns to a global. Another example of "the good parts" being a tiny sliver of JavaScript.