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.
- All episodes are in the TypeScript from Zero playlist.
- Versions used: Node.js 26.13.0, npm 11.20.0, TypeScript 7.0.2.
Setup
We start in the terminal and open the project in VS Code:
$ touch booleans.ts1. 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.
const age = 20;
const hasTicket = true;
console.log(age > 18);
console.log(age === 20);
console.log(age !== 20);
console.log(age >= 21);$ node booleans.ts2. 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.
console.log(age > 18 && hasTicket);
console.log(age < 18 || hasTicket);
console.log(!hasTicket);$ node booleans.ts3. 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.
$ node booleans.ts4. 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.
$ npx tsc --noEmit booleans.ts5. 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.
$ npx tsc --noEmit booleans.ts$ node booleans.tsRecap
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.