Developer. Feminist. Ecologist. Used to be a protection Paladin.

  • 0 Posts
  • 21 Comments
Joined 1 year ago
cake
Cake day: June 13th, 2023

help-circle



















  • in javascript a property is truthy if it exists

    myThing.property = "some string"
    
    if (myThing.property) { // true
      // do something
    }
    

    It works with everything except of course for falsy values

    myThing.number = someNumberThatShouldNotBeEqualToZero
    
    if (myThing.number) {
      // do something very important with that number that should not be equal to zero
    }
    
    // This can fail at anytime without warning
    

    So you’ve got to be extra careful with that logic when you’re dealing with numbers.

    I am not saying it’s wrong though. I’m saying it’s often annoying.