Does an empty string evaluate to true or false?

  • burner918-1309215386394300457

    Sean

    5 months ago

    Why does an empty string here evaluate to true? I assumed that this would be false but this evaluates to true.
    1309215386620923987-image.png
  • lucasg-1309216214018560100

    Lucas G

    5 months ago

    An empty string is a truthy value because it is not technically null or undefined
  • burner918-1309216828882423981

    Sean

    5 months ago

    Thanks Lucas. So am I reading this wrong then?
    1309216828668776542-image.png
  • lucasg-1309217252587077672

    Lucas G

    5 months ago

    Sort of
  • There's some mixups going on
  • Those are actually JavaScript's falsy values
  • But the And operator takes anything that's not null as true
  • burner918-1309217689868435457

    Sean

    5 months ago

    Hmm..
  • lucasg-1309217696789037128

    Lucas G

    5 months ago

    I've never thought much about it
  • Could be a bug tbh
  • Or rather, it probably technically is since the Boolean node behaves the same way
  • But its description says 0 should be false
  • But it returns true
  • I've always defaulted to null so I've never thought about it 🤔
  • burner918-1309218221009797160

    Sean

    5 months ago

    Yeah, which is why it confused me. I tried inserting the Boolean node and that didn't work either. So wanted to check so that I don't have to keep adding an unnecessary condition to force an empty string to be considered as falsy
  • lucasg-1309218506213953618

    Lucas G

    5 months ago

    I use the Equals/Not Equal nodes
  • If input doesn't equal empty string
  • burner918-1309218776558075986

    Sean

    5 months ago

    To your earlier point, am I understanding correctly that you use a Defaults to Null for any empty string so that it's forced to be null (falsy) instead of an empty string (true)?
  • lucasg-1309219033396150303

    Lucas G

    5 months ago

    No, an empty string won't use a default to value
  • It would be an empty string
  • burner918-1309219145128083458

    Sean

    5 months ago

    But it would be truthy, right?
  • lucasg-1309219151763603468

    Lucas G

    5 months ago

    I think default to is for undefined/null values
  • lucasg-1309219467355492432

    Lucas G

    5 months ago

    Default to returns whatever is not false. Which I guess is the same logic behind the other ones
  • Null/undefined use the default to value
  • burner918-1309219576403329046

    Sean

    5 months ago

    I'm tryin to set a default to a component attribute, so that if I don't provide it in the instance, then it defaults to false. But if I don't provide it, i.e. it's an empty string, then it seems to evaluate to true -- so now I have to explicitly remember to set it.
  • lucasg-1309219594946478183

    Lucas G

    5 months ago

    Empty string is not being considered a falsy value
  • Potentially a bug
  • I will check with the team actually
  • burner918-1309219796788973590

    Sean

    5 months ago

    Thanks Lucas.
  • lucasg-1309219873632681994

    Lucas G

    5 months ago

    If you don't provide a value to an attribute it is undefined, not an empty string
  • Use default to false
  • burner918-1309220249442451526

    Sean

    5 months ago

    Ah, okay. Thanks Lucas
  • olumise-1309454279337185280

    Olumise

    5 months ago

    Hi Lucas, I thought an empty string is falsy while an empty array and object is truths
  • Tod-1309454280679358475

    Tod

    5 months ago

    Great energy @Olumise! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • lucasg-1309544755834785792

    Lucas G

    5 months ago

    Not in toddle
  • I brought it up with the team and it’s been clarified and updated in the docs now
  • Null and undefined resolve to false
  • lucasg-1309545921960214549

    Lucas G

    5 months ago

    Either way, I recommend setting actual null, false, true values instead of relying on falsy/truthy
  • erikbeus-1309608165599481876

    Erik Beuschau

    5 months ago

    Docs can be found here. We hope to improve the docs further going forward 🤞 https://toddle.dev/docs/show-hide-formula#Basic%20Concept
  • olumise-1309811855274938388

    Olumise

    5 months ago

    Thank you for the clarification @Lucas G @Erik Beuschau