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