Binary Operators

By far the most commonly used operators are binary operators. A binary operator is not an operator that performs actions only on 0’s and 1’s, but rather an operator that has two operands. All the comparison operators are binary operators.

Coercion

Some languages (including JavaScript) sometimes coerce type when working with operands of different types. This means that the data type of one of the operands is changed so that the operator can perform its action. You have seen JavaScript coercing type when we tried to add '2' + 2. The number 2 was coerced to become a string, so the output was '22'. Type coercion can be really useful if you know what you are doing, but it can be quite dangerous in some situations. If you try '2' ...

Get Learning to Program 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.