• ulterno@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    7 hours ago

    Same as ?

    std::optional<bool> role;
    
    if (role.value())
    { std::cerr ("User is admin");}
    else if (!role.value())
    { std::cerr ("User is not admin");}
    else if (!role.has_value())
    { std::cerr ("User is not logged in");}
    

    Here has_value() should have been checked first, but the JS seems kinda fine.
    Which is it?

    • shape_warrior_t@programming.dev
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 hours ago

      a === b returns true if a and b have the same type and are considered equal, and false otherwise. If a is null and b is a boolean, it will simply return false.