52
lorentz
4y

I love how JS lets you throw absolutely nothing.

Comments
  • 16
    I, too, want to throw undefined out of the window sometimes
  • 17
    Drunken languages and people want use it for backend server ... What a mess
  • 1
    And... What will happen in the result?
  • 2
    That's why you could get the error "undefined is undefined"
  • 4
    There are a few types of nothing:

    null and u n d e f i n e d
  • 2
    @iiii It prints "undefined" as the error message.
  • 2
    @jak645 lol same for php
  • 4
    @OmerFlame see, unrefined scares me.
    With null at least, we know that there's certainly nothing there but undefined is just too inconclusive to me.
  • 3
    @Ranchonyx Undefined might be the closest thing you can get to nothing in JS because a null value can be coerced to the number 0 (for example if you do null + 1).

    In truth though, I believe there is no nothing value in JS. Anything can be converted to a boolean.
  • 3
    @Ranchonyx undefined means that there was never meant to be anything there. In this case it's stupid because an exception means that something happened, and there should be an object describing it.
  • 2
    There was some lengthy explanation as for why to use undefined instead of null by someone involved in TypeScript, but I can't find it (I'm only finding this: https://github.com/Microsoft/...), although I also feel like null is a bit more explicit. Something that is only declared (but not initialised) will equal undefined in a strict comparison (and I'm a proponent for strict comparisons whenever possible).

    This is yet another instance of "JavaScript allows me to do stupid shit, hence I must do stupid shit". Well, you are allowed to jump off a bridge, but will you?
  • 2
    Never tried to kick a ball, but miss?
    Never step on that nonexistent last step?
  • 0
    @kamen undefined is used in typescript for optional things because javascript will leave an unassigned parameter on undefined and this allows assigning optional parameters to optionals. Basically since javascript will produce undefined a lot but null almost never it's better to use undefined if you want to use only one of them.
  • 0
    @kamen I agree. I would also suggest treating null values as something you that goes between client and server.
  • 0
    @theuser useful af

    /s
  • 0
    @nitwhiz yes but php is create for that not javascript
  • 1
  • 1
    after i had a good giggle i had to explain that to my so. that was not as much fun.
  • 1
    @erroronline1 Yeah now that you mention this joke involves a lot of concepts.
  • 0
    Why don't browsers support another language instead of js......
  • 0
    @firecracker It's like asking for everyone to start using Betamax when VHS was all over the place, only that with browsers there hasn't been a proper alternative. There is Wasm, but its use is limited IMO.
  • 0
    @kamen WASM works really well and its startup overhead will become negligible once the standard glue JS is cached in every browser, but there aren't many languages that are high level, single threaded and have a tiny executable size (which is essential on the web).
  • 1
    To statically link WASM with something like Qt would be to have the user load over 100mb, which you can only do _after_ your app diid something remarkable, in order to prevent losing customers.
  • 0
    Could probably do this in C# with:

    throw default(Exception);
  • 0
    @Lor-inc I guess you would have to cache the lib files of whatever HTML and CSS alternative you're gonna use and create some kind of "first setup" loading view for the users.

    Unless you've got layers upon layers of frameworks, you can create something meaningful in HTML and CSS with almost zero loading times from a user perspective.
  • 0
    @theuser Now that you mentioned, I think HTML and CSS are excellent GUI building tools, so there's also the option of creating an interface between the DOM/CSSOM and WASM, which would allow to skip the GUI framework.
  • 1
    People be bitching about javascript when C lets you define true as false and vice versa.
  • 0
    @hashedram That isn't a problem. It isn't up to the language to prevent you from doing stupid shit, as long as it makes sure you know you're doing stupid shit. JS text-number arithmetic and truthyness is considered bad because it isn't obvious that your variable happens to be text.
  • 0
    @Lor-inc what a really long way to say "I'm gonna cherry pick".

    As with C, JavaScript is obvious if you know what you're doing.
  • 0
    @hashedram You're not supposed to care about types in JS, but because the defaults for casting are stupid you still have to.
  • 0
    You wouldn't redefine true by accident.
Add Comment