DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Day 88/100 Truthy and Falsy
Rio Cantre
Rio Cantre

Posted on • Originally published at dev.to

Day 88/100 Truthy and Falsy

To know the value of a function and use a proper boolean may conclude that it is easier to distinguish which one is not real to begin with.

banner

Overview

let myVariable = 'I Exist!';

if (myVariable) {
Β Β Β console.log(myVariable)
} else {
Β Β Β console.log('The variable does not exist.')
}
Enter fullscreen mode Exit fullscreen mode
  • The code block in the if statement will run because myVariable has a truthy value; even though the value of myVariable is not explicitly the value true, when used in a boolean or conditional context, it evaluates to true because it has been assigned a non-falsy value.
  • So which values are falsyβ€” or evaluate to false when checked as a condition? The list of falsy values includes:
    • 0
    • Empty strings like "" or ''
    • null which represent when there is no value at all
    • undefined which represent when a declared variable lacks a value
    • NaN, or Not a Number

Code Snippets

let username = '';
let defaultName;

if (username) {
Β Β defaultName = username;
} else {
Β Β defaultName = 'Stranger';
}
Enter fullscreen mode Exit fullscreen mode

a11y myths

Accessibility can only be tested by disabled people

Well, usually disabled people are the best testers - they use assistive technologies full time. However, everyone can learn how to test websites for accessibility.

resources

Top comments (0)

The Complete Guide to Full Stack Web3 Development

The most important tools, protocols, and frameworks for building full stack web3 apps, and most importantly - how to put everything together to lay the groundwork for building out any of your own ideas in the future.