Day 88/100 Truthy and Falsy

riocantre

Rio Cantre

Posted on December 12, 2021

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

💖 💪 🙅 🚩
riocantre
Rio Cantre

Posted on December 12, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Day 88/100 Truthy and Falsy
100daysofcode Day 88/100 Truthy and Falsy

December 12, 2021

Day 86/100 Font Weight
100daysofcode Day 86/100 Font Weight

December 10, 2021

Day 81/100 Variables
100daysofcode Day 81/100 Variables

December 5, 2021

Day 80/100 Semantics
100daysofcode Day 80/100 Semantics

December 4, 2021

Day 79/100 Tables
100daysofcode Day 79/100 Tables

December 3, 2021