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
-
Lensflare17182324dTo be fair, that‘s also true for other languages which have garbage collection or automatic reference counting.
-
Fast-Nop39368324d@Lensflare What makes JS more insidious here is that function-local variables are actually global by default unless you make them explicitely local.
-
Fast-Nop39368324d@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.
-
Lensflare17182324d@localpost no it‘s bad because it violates the principle of "the correct thing should be the default"
-
thebiochemic3019324d@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)
-
Pogromist2500311dfunction func() {
var localVar = "STRING";
}
func();
console.log(localVar);
Uncaught ReferenceError: localVar is not defined
In which way are they global by default? -
Pogromist2500311dOnly 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-Nop39368311d@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?
-
Pogromist2500311d@Fast-Nop i'm not thinking in pythonic way so it's stupid to think that function local variables are global by default
-
Fast-Nop39368311d@Pogromist You just proved it yourself. No special token before? It's global. You might want to google what "default" means.
-
Pogromist2500311d@Fast-Nop so you just want javascript to be like other languages and warn you that you are declaring global variable?
-
Pogromist2500311d@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-Nop39368311d@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. -
Lensflare17182310d@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