🖥️
Intro to Computer Science (ICS3U/C)
  • An Introduction to Computer Science
  • Videos & Slides
  • Unit 1: In the Beginning
    • The History of Computers
    • Binary & Logic
      • Bits and Bytes (Binary)
      • Transistors (Changing Bits)
      • Logic Gates
        • Poster
        • Logic.ly
    • The Parts of a Computer
  • Unit 2: Intro to Code
    • How Do We Code?
      • Coding Conventions (Rules)
      • Commenting Code
    • What is HTML?
      • Hello World! (in HTML)
      • HTML Slideshow
    • Hello World!
    • Input / Output
      • The Console
      • Prompt, Alert, Confirm
    • Variables & Data
      • Strings (Text)
      • Numbers (Values)
        • Converting & Rounding
        • The Math Object
          • Random Numbers
      • Booleans
        • Truthiness
      • Arrays
  • Unit 3: Control Flow
    • Conditionals (if this, do that)
      • If...Else
        • Logical Operators
      • Switch / Case
      • Ternary Operators
    • Loops (Repeating Code)
      • For...Loop
      • While & Do/While Loops
    • Debugging
  • Unit 4: Functions
    • Functional Programming
    • User Defined Functions
      • Hoisting and Scope
    • Calling a JS Function
  • TL;DR
    • Programming Basics
    • Slideshows & Demos
    • Javascript Syntax Poster
  • Advanced Topics
    • Recursion
    • Structures & Algorithms
    • Mmm... Pi
  • External Links
    • Typing Club!
    • repl.it
    • Khan Academy
    • Geek Reading
    • ECOO CS Contest
Powered by GitBook
On this page
  • Falsy
  • Truthy
  1. Unit 2: Intro to Code
  2. Variables & Data
  3. Booleans

Truthiness

PreviousBooleansNextArrays

Last updated 6 years ago

Javascript (and other languages) have something called . Ok, it's actually called or . It is the idea that we can infer something is true, similar to assuming.

Falsy

If something does not exist (like NaN) or has a value equating to zero, it is considered false. For example, an empty string of "" would be considered false. It has no value.

Truthy

If the data has value (other than specifically NaN, zero, or false) it is considered true, because it has value. For example, 1 == '1' will result in true because they are equal in value (Javascript converts on-the-fly). However, 1 === '1' will return false because they are not exactly equal (one is a numeric value, the other a string).

NaN stands for Not a Number. Think of it like "undefined" or "does not exist". Note: division by zero gives an answer of infinity.

Truthiness
Truthy
Falsy