🖥️
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
  1. Unit 2: Intro to Code
  2. Variables & Data

Booleans

There are 10 kinds of people in the world: those who understand binary and those who do not.

PreviousRandom NumbersNextTruthiness

Last updated 6 years ago

By now you probably know what a is and you may have heard about or . Together, they are the bread and butter that makes programming work. We can compare two or more values, utilize a boolean for situations with only two states, or combine values using boolean algebra in order to control our code.

In Javascript, anything with a value is considered to be true (see ). We can use to return a true or false value. For example: (10 < 6) // false. Strongly typed languages such as C++ and Java have a boolean primitive type. JS also has a boolean type but it is loosely (or dynamically) typed, so it can take on other values as well.

Later in our programming adventure, we will even create our own functions that return a boolean value in order to state if something happened or not.

Boolean Logic

You may have seen boolean logic for . This same process can be applied to boolean values in code.

Operator

Symbol

Example(s)

Not

!

!(4 < 10) = false

And

&&

(true && false) = false

(3 < 5 && 7 > 1) = true

Or

||

(true || false) = true

(5 > 10 || 1 == 1) true

Nand

!(x && y)

!(true && false) = true

!(3 < 5 && 7 > 1) = false

Nor

!(x || y)

!(true || false) = false

!(5 > 10 || 1 == 1) = false

boolean value
boolean algebra
George Boole
truthiness
logic gates
comparison operators