Comparison operators

TypeScript supports the following comparison operators. To understand the examples, you must assume that variable A holds 10 as value and variable B holds 20 as value:

Operator

Description

Example

==

Checks whether the values of two operands are equal or not. This operator uses type coercion. If yes, then the condition becomes true.

(A == B) is false. A == "10" is true.

===

Checks whether the value and type of two operands are equal or not. This operator doesn't use type coercion. If yes, then the condition becomes true.

A === B is false. A === "10" is false.

!=

Checks whether the value of two operands are equal or not. If the values are not equal, then the condition becomes true. This operator ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.