Search⌘ K
AI Features

Booleans

Explore how JavaScript represents true and false values with booleans and learn to create these using comparison operators. Understand the difference between strict and loose equality checks, and why strict operators are preferred to avoid type conversion errors.

Booleans

At its most basic level, a computer is a series of on and off switches, a set of 0s and 1s that flip back and forth to compute things.

The concept of using binary values to represent information (0 and 1, true and false) is so fundamental to computation that JavaScript, along with most other programming languages, has a dedicated type to these values, referred to as a boolean.

Creating a boolean value

Boolean values can be created by assigning a value of true or false to a variable.

Node.js
var theTruth = true;
var aLie = false;
console.log(theTruth);
console.log(aLie);

Booleans from comparison operators

...