Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Lensflare17095318dTo be fair, that‘s also true for other languages which have garbage collection or automatic reference counting.
-
Fast-Nop39378318d@Lensflare What makes JS more insidious here is that function-local variables are actually global by default unless you make them explicitely local.
-
Fast-Nop39378318d@localpost It's not only you have to, but it also doesn't even throw an error if you don't. Sane people try to minimise the scope of variables. "Global by default" goes against this, hence it's bad design and was bad already back in the 90s.
-
Lensflare17095318d@localpost no it‘s bad because it violates the principle of "the correct thing should be the default"
-
thebiochemic3019318d@Lensflare even rust can leak memory. It's even considered safe. But there are atleast concrete design reasons behind it (like FFI for example, or creating 'static lifetime stuff)
-
Pogromist2500305dfunction func() {
var localVar = "STRING";
}
func();
console.log(localVar);
Uncaught ReferenceError: localVar is not defined
In which way are they global by default? -
Pogromist2500305dOnly if you create variable without these "var, let, const" declarators it means you would set property to global context object "window"
like window.localVar = "STRING";
If you write "use strict"; it doesn't allow such declarations. -
Fast-Nop39378305d@Pogromist So you specify one of the extra tokens to deviate from the global default and then ask how it is global by default? Really?
-
Pogromist2500305d@Fast-Nop i'm not thinking in pythonic way so it's stupid to think that function local variables are global by default
-
Fast-Nop39378305d@Pogromist You just proved it yourself. No special token before? It's global. You might want to google what "default" means.
-
Pogromist2500305d@Fast-Nop so you just want javascript to be like other languages and warn you that you are declaring global variable?
-
Pogromist2500305d@Fast-Nop i was confused with php at first when you needed to declare global variable as "global $var;" before accessing it inside function.
-
Fast-Nop39378305d@Pogromist No qualifier should have the minimum scope, i.e. that should be equivalent to "let". That would be proper language design.
Obviously, you'd then need some sort of qualifier for global, such as a hypothetical "glob" or something.
It's just annoying when a language kicks you down the wrong road by default. -
Lensflare17095305d@Fast-Nop why would you need a qualifier for global? If you want it to be global, declare it in global scope.
JS devs be like...
joke/meme
javascript