liveBook · Manning

Equality

As explained in Pro Angular 16

The JavaScript identity operator compares operands without type coercion and requires their values and types to match.

Strict equality uses === to compare both value and type without coercion. Unlike ==, it does not convert operands before deciding whether they match. section 3.4.7

Number versus string

let firstVal: any = 5; let secondVal: any = "5"; if (firstVal === secondVal) { console.log("They are the same"); } else { console.log("They are NOT the same"); } // They are NOT the same

Use === when a comparison must reject values whose types differ. TypeScript can also flag comparisons between inferred number and string types as always false.

How Pro Angular 16 covers it

How deep it goes
Defines coercion and demonstrates behavior with listings, but does not develop the equality algorithm’s internal edge cases.
Examples
Compares numeric 5 with string "5", prints the result, and contrasts explicit any annotations with inferred TypeScript types.
What it assumes
Assumes basic JavaScript conditionals and types while teaching the distinction between coercing and non-coercing comparisons.
What you can do after
Apply strict equality in conditional statements and recognize when TypeScript rejects comparisons between incompatible inferred types.
How it connects
Connects strict equality with type coercion, loose equality, conditional statements, TypeScript type inference, and truthy or falsy values.

Also explained in

Compare how 4 books explain equality →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.