2
msdsk
1y

I've been working with JavaScript for nearly a decade now and yet I still get fooled from time to time by the fact that 0 == false.

Comments
  • 2
    I nearly can't imagine a case that going wrong. if(number) works exactly as if(bool). Enlighten me
  • 3
    yeah but 0 !=== false
  • 5
    To be fair, lots of other languages have this, too.

    JS takes many of the worst aspects of other languages, combines it with some specific idiotic novel ideas, takes off its "scripting language" label and cheekily replaces it with a "programming language" label.

    And then it proudly presents itself as the most popular language. Because popular means good, obviously.
  • 2
    @Lensflare while writing a language myself I had many side effects what is considered functionality in python / js. Or like in Rust for example, last var get always returned. I got that functionality for free!
  • 3
    You can imagine how many of the details of unwanted side effects of some design decisions got forgotten and confused over time and ended up being promoted as nice features by devs with Stockholm syndrome who are held hostage by their favorite language.
  • 2
    @Lensflare
    Not to mention that the web has to be backwards compatible because of course so we are stuck with all those idiotic decisions
  • 2
    How is this an issue? Most languages I have used equate 0 to false.
  • 3
    I literally have to keep in mind to parseInt a value that I want to be taken as an integer.
    I don't trust JavaScript.
  • 1
    @SidTheITGuy people that passing integer to html attributes can *** in a fire. Always format. I never had unexpected values
  • 3
    @retoor I mean more in this way -

    if (number > 0) lets say number is dynamic

    so i do

    if(parseInt(number) > 0) cuz who knows JS will take it as boolean.

    It's more towards an internal logic that has to be written.
  • 1
    @Lensflare "Because popular means good, obviously."

    We need to find the fucker who invented the whole idea, tie him to a chair, beat him with hammers, and leave him bleeding in the moonlight.
Add Comment