7

Speaking of JS gotchas. Why is there a null and undefined? I guess undefined doesn't exist, but null is it exists, but is null? Had a bug related to this. I was checking for null, but undefined was getting in there even though I defined the variable as null beforehand. All I can guess is some assignment shoved undefined in there. But that just doesn't make sense to me. So an existing variable can be undefined as well? lol

I am glad this is not my primary language for heavy lifting. Fuck this noise.

I was going to do this as a rant. But it turned into an ironic joke. I am adding an old meme, but it checks out for accuracy.

Comments
  • -1
    An antigenocidal* maniac.

    German doesnt count
  • 1
    No null is not undefined, they are different thing. Think of it more like symbols or jungian archetypes. They actually have deep spiritual meaning to me.

    Meditate for an hour and maybe you will get it.
  • 2
    For real in practice they are just false. Just test for !!variable and everything is casted to boolean, problem solved.
  • -1
    Also be careful around this whole trump shit. He is german.
  • 1
    @antinazi Yeah, I ended up doing falsy test to catch both null and undefined.

    Here, enjoy this programming dad joke:

    How come every time I get a vtable error I always look it up and think I need a destructor, but in reality I remember that it is because I made a class with a Q_OBJECT macro in a cpp file? Why does Qt moc me so...?
  • 3
    For this specific bullshit I made myself a class with a static method as follows:

    Guard.AgainstNullish<T>(val: T): asserts val is Exclude<val, undefined | null>

    Or at least something like that.

    This actually is properly typed so that if you use an IDE which does the whole typescript shebang, it'll ensure that below the Guard.AgainstNullish(); call, the passed parameter is never null or undefined.

    Do not use plain JavaScript, it's a kick in the balls ready to happen.
  • 1
    @Demolishun @retoor explains the joke alseblieft.
  • 1
    @antinazi Qt moc, don't you get it?
  • 1
    @Ranchonyx It is used as a scripting tool for QML. Not sure I could even get Typescript to work with it.
  • 1
    @retoor queue tea mock?
  • 1
  • 0
    @Demolishun you wouldn't have this issue with retoorscript
  • 1
  • 4
    @Demolishun take this dad joke
  • 2
    Skill issue.
  • 2
    Seriously though, semantically speaking, I use undefined as “untouched nothing” and null as “deliberate nothing”. If something in my code is null, it means I set it. If it’s undefined it means it was the default.
  • 1
    @kiki in my code I was deliberately seeing to null on variable definition. But a later assignment was putting in undefined. No idea which call it was yet (another thing to figure out). So checking for falsely was more appropriate in this case. The logic is kinda messy and probably needs redone.
  • 1
    @retoor i dont get it
  • 0
    Null is the substance of what is not. But it is still something, whereas undefined is something that is defined as a paradox, because it exists but at the same time it does not. Null is undefined, but undefined is not null, and vice-versa.

    I think about it a lot at night while I masturbate.
  • 1
    @Demolishun yes, I use falsy and truthy conditions in JS. I don’t care if it’s undefined or null, I only care that it’s falsy
  • 0
    I don't even remember anymore

    I never used nulls though
  • 1
    @Demolishun !!value might be nothing if a zero. can't remember if empty strings count as false but I do believe arrays didn't

    I actually think I ended up using ? operator when that came into being but I can't remember what I used prior to that 🤔

    https://developer.mozilla.org/en-US...
  • 1
    Falsy is kind of dangerous since zero or empty strings trigger it.

    You can just coercing compare against either null or undefined to catch both and not have falsy positives, as in...

    null == undefined //true
    null === undefined //false
  • 1
    Also, on a more architectural matter, the whole null vs undefined really comes from the C implementation.

    Null is null in that sense, like, a symbol that exists, but has no value.

    (JS also historically had trouble with the fact that NULL was 0.)

    Undefined is a byproduct of interpreted languages. In a compiled language, it makes no sense because it won't even compile, but when you execute line by line, especially as REPL, you are bound to encounter the situation of someone using a symbol that's not defined. Hence undefined.

    The comparison rules, I agree are weird, but probably the lesser evil in trying to not break existing code.

    Undefined is also, as a clutch, used as a semantical "void".
Add Comment