Re:Structure and Interpretation of Computer Programs – JavaS...
by nobleach on Wednesday December 18, 2019 @11:39AM
(#21826613)
I'd agree that global declaration is far more egregious. A sibling comment recommends a linter, and I'd probably agree. It's sad that it was ever allowed as one that is copying and pasting code to another location can easily cause this case to happen.
Re:Structure and Interpretation of Computer Programs – JavaS...
by jimws on Wednesday December 18, 2019 @11:31AM
(#21826517)
Problems like this can be easily caught by linters like eslint or standardjs.
Re:Structure and Interpretation of Computer Programs – JavaS...
by s_y_n_t_a_x on Wednesday December 18, 2019 @12:21PM
(#21827075)
No JS developer would do that.
We all know that is global.
Nowadays you use `const` or `let`.
Any JS developer will have a linter that will tell them incase they somehow made that mistake.
Re:Structure and Interpretation of Computer Programs – JavaS...
by tombert on Wednesday December 18, 2019 @12:49PM
(#21827337)
Eh, I actually like JS but I have definitely forgotten to add a "var" or "let" a few times, or sometimes I will do it correctly, get a bit overzealous with cutting, and accidentally remove the initial var declaration.
I'm not saying that it breaks the language, but it definitely is irritating, especially if you're not using a linter.
Re:Structure and Interpretation of Computer Programs – JavaS...
by s_y_n_t_a_x on Wednesday December 18, 2019 @07:36PM
(#21830983)
I come from Lua so I'm used to declaring local variables with "local".
Also, I like knowing which variables won't be reassigned (const), and which will (let).
Re:Structure and Interpretation of Computer Programs – JavaS...
by shakna on Thursday December 19, 2019 @04:36AM
(#21833359)
Whilst I do find it irritating, I don't mind about the scope default so much, but I've certainly run into it (forgetting to specify) a lot.
Mostly because JS is not the only language that I'll be working with at a time, and if I'm dancing between three or four and they have similar syntax, then mistakes creep in.
Re:Structure and Interpretation of Computer Programs – JavaS...
by jdminhbg on Wednesday December 18, 2019 @05:14PM
(#21830037)
That's all fine, but those are all workarounds for a design mistake in the language.
Re:Structure and Interpretation of Computer Programs – JavaS...
by s_y_n_t_a_x on Wednesday December 18, 2019 @07:43PM
(#21831033)
No it's a choice, apparently people can't have one.
x = 5;
(no var declaration). Extremely easy to do by accident. Lots of these will be left for backwards compatibility. In JS errors often go silent and I developed a strong dislike for any language that does that, including Vimscript and Lua (and I do like Vim).