Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Truth About Truthy & Falsy

The Truth About Truthy & Falsy

Deck demonstrating which values are truthy / falsy w.r.t a programming language.

Swaroop SM

April 10, 2015
Tweet

More Decks by Swaroop SM

Other Decks in Technology

Transcript

  1. - TRUTHY: If the value isn’t literally “true” but evaluates

    to true. - FALSY: If the value isn’t literally “false” but evaluates to false. What is it?
  2. var a = 0; if(a) { alert(“I’m TRUTHY :)”); }

    else { alert(“I’m FALSY. Feel so proud. :D”); } The Confusion
  3. TRUTHY - true - 0 - “” - [] -

    {} Ruby FALSY - false - nil
  4. Ruby on Rails present? - !blank? - 0 - true

    blank? - nil - “” - [] - {} - false - whitespace
  5. Python TRUTHY - True - 1 FALSY - False -

    None - 0 - [] - “” - {}
  6. JavaScript TRUTHY - true - “0” - [] - {}

    FALSY - 0 - false - “” - undefined - null - NaN