14
Fast-Nop
355d

JS devs be like...

Comments
  • 8
    @aviophille Nice face reveal.
  • 2
    This describes my brain.
  • 6
    To be fair, that‘s also true for other languages which have garbage collection or automatic reference counting.
  • 2
    @Lensflare What makes JS more insidious here is that function-local variables are actually global by default unless you make them explicitely local.
  • 2
    "JS bad because you have to use a keyword to declare a local variable"
  • 4
    @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.
  • 2
    @localpost no it‘s bad because it violates the principle of "the correct thing should be the default"
  • 1
    @aviophille Nope, it's common sense - something you ofc lack.
  • 0
  • 1
    @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)
  • 1
    @thebiochemic yup. That was my point also.
  • 0
    function func() {
    var localVar = "STRING";
    }

    func();
    console.log(localVar);

    Uncaught ReferenceError: localVar is not defined

    In which way are they global by default?
  • 0
    Only 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.
  • 0
    @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?
  • 0
    @Fast-Nop i'm not thinking in pythonic way so it's stupid to think that function local variables are global by default
  • 1
    @Pogromist You just proved it yourself. No special token before? It's global. You might want to google what "default" means.
  • 0
    @Fast-Nop so you just want javascript to be like other languages and warn you that you are declaring global variable?
  • 0
    @Fast-Nop i was confused with php at first when you needed to declare global variable as "global $var;" before accessing it inside function.
  • 1
    @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.
  • 2
    @Fast-Nop why would you need a qualifier for global? If you want it to be global, declare it in global scope.
Add Comment