PricingDocsAcademy
Bluesky ...
Tue, Dec 3, 2:29 AM

Does an empty string evaluate to true or false?

  • /attachments/1309215386394300457/1309215386620923987/image.png

    Sean

    11 days ago

    Why does an empty string here evaluate to true? I assumed that this would be false but this evaluates to true.
    image.png
  • Lucas G

    11 days ago

    An empty string is a truthy value because it is not technically null or undefined
  • /attachments/1309215386394300457/1309216828668776542/image.png

    Sean

    11 days ago

    Thanks Lucas. So am I reading this wrong then?
    image.png
  • Lucas G

    11 days 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
  • Sean

    11 days ago

    Hmm..
  • Lucas G

    11 days 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 🤔
  • Sean

    11 days 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
  • Lucas G

    11 days ago

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

    11 days 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)?
  • Lucas G

    11 days ago

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

    11 days ago

    But it would be truthy, right?
  • Lucas G

    11 days ago

    I think default to is for undefined/null values
  • Lucas G

    11 days 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
  • Sean

    11 days 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.
  • Lucas G

    11 days ago

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

    11 days ago

    Thanks Lucas.
  • Lucas G

    11 days ago

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

    11 days ago

    Ah, okay. Thanks Lucas
  • Olumise

    10 days ago

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

    10 days ago

    Great energy @Olumise! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • Lucas G

    10 days 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
  • Lucas G

    10 days ago

    Either way, I recommend setting actual null, false, true values instead of relying on falsy/truthy
  • Erik Beuschau

    10 days 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

    9 days ago

    Thank you for the clarification @Lucas G @Erik Beuschau

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.