M Logo
๐Ÿ“ TypeScript from Zero ยท Part 5 of 50

TypeScript Booleans and Comparisons: === vs ==

November 6, 2026

Welcome to episode 5 of TypeScript from Zero, a series for complete beginners (no JavaScript needed). Welcome back to TypeScript from zero! Today: booleans and comparisons. A boolean is a value that is either true or false. A new file called booleans.ts. Every code block below is the code from the video, ready to copy; run each file to see the output.

Setup

We start in the terminal and open the project in VS Code:

bash
$ touch booleans.ts

1. Compare

We make a constant age, and a constant has ticket, which is true. A comparison asks a question, and the answer is a boolean. Is age greater than eighteen? True. Is age exactly twenty? Triple equals asks that, and the answer is true. Not equals gives false, and so does greater or equal twenty one.

ts
const age = 20;
const hasTicket = true;
console.log(age > 18);
console.log(age === 20);
console.log(age !== 20);
console.log(age >= 21);
bash
$ node booleans.ts

2. Logic

We combine booleans with three words made of symbols. Two ampersands mean and: both sides must be true. Two vertical bars mean or: one side is enough. An exclamation mark means not: it flips the value.

ts
console.log(age > 18 && hasTicket);
console.log(age < 18 || hasTicket);
console.log(!hasTicket);
bash
$ node booleans.ts

3. Loose

Now a trap. Double equals, with only two signs, compares loosely. It turns the number five and the text five into the same thing, and says true. Node does not complain.

bash
$ node booleans.ts

4. tsc

tsc does complain: this comparison appears to be unintentional, because the types number and string have no overlap. TypeScript saw that we compare a number with text, which is almost always a mistake.

bash
$ npx tsc --noEmit booleans.ts

5. Fix

The fix: turn the text into a number first, and use triple equals. Always use triple equals, never double. tsc is quiet, and the answer is true, for the right reason.

bash
$ npx tsc --noEmit booleans.ts
bash
$ node booleans.ts

Recap

Today: booleans are true or false, comparisons give booleans, and, or and not combine them, and always use triple equals. Next episode: decisions with if, else and switch.

ยฉ 2026 All Rights Reserved By Mahmudul Alam