10

God I hate JavaScript.

Why on earth would some variable * somthing.other (where somthing is undefined) result in 653957364??????

Comments
  • 8
    Because undefined means any result is OK.

    If you had been using C/C++, the compiler would have made that faster by optimising the undefined function away. Or maybe even the whole program.
  • 3
    Garbage value maybe?
  • 4
    What? Don't you get NaN?
  • 9
    Maybe you should be asking yourself why that something is undefined and why you don't have a check for that.
  • 3
    (undefined).something should trow an error...
  • 1
    JavaScript does wierd things if you let it.
    Go back and check "something" is actually an expected value / type before making use of it.
  • 4
    @Fast-Nop I would hope the compiler just optimises the developer away in that scenario.
  • 7
    Undefined behavior is undefined behavior.

    The language doesn't replace you as the developer -- and shouldn't strive to.
  • 3
    @kwilliams Confucius said, always check your return codes.
  • 1
    @kamen @C0D4 @Root that's the other wiered thing, the check I put in does mot work.
  • 4
    @kolaente Then maybe your check isn't the best. Care to share a more specific code example?
  • 1
  • 1
    @kolaente I'm not even blaming or accusing you or whatever, I'm just curious what's happening, maybe I can learn something new from it too.
  • 0
    @rendezvous
    JS always has everything defined.

    Since when JS is a strongly typed lang? If you can have a var that can change types mid run then you might crash the code by putting shit in that var. You wouldnt be able to change the type in the strongly typed lang.

    Please explain if i understood something incorrectly.
  • 0
    @rendezvous
    Thanks.
  • 1
    @kamen So, this is a vue js app where I set some element when the user clicks on a thing. This thing is draggable, when the user then stops dragging it a function gets called to do some calculations based on where it was dragged, based on the element which was set when the user clicked. Sometimes, the element is not set when the user finishes dragging (I suspect because of a race condition or something like that), so to be sure the element is set, I have a loop in the drag handler which waits until the element is not null/undefined. And that one does not work.

    The code is here: https://kolaente.dev/vikunja/...

    (Sorry for being unresponsive, I was busy with other stuff)
  • 0
    @kolaente I'm not familiar with Vue, but I'd suggest looking into reasons why the mouse up event doesn't fire.
Add Comment