Search⌘ K
AI Features

Relational and Boolean Operators

Explore JavaScript relational and Boolean operators to understand how comparisons and logical operations work across different data types. Learn the rules for less than, greater than, logical AND, OR, and NOT operators, and see examples that clarify their use in coding.

Relational operators

Besides the equality operators, JavaScript defines four relational operators, similar to other programming languages.

These are less than (<), greater than (>), less than or equal to (<=), and greater than or equal to (>=). Each returns a Boolean value representing the result of the comparison.

Operand rules

These operands work according to these rules:

  1. If both operands are numbers, a numeric comparison is carried out.

  2. If both operands are strings, the character codes of each corresponding character in the string are compared.

  3. If one operand is a number, the other operand is converted to a number, and a numeric comparison is performed.

  4. If an operand is an object, valueOf() is called, and its result is used to perform the comparison according to the previous rules. If valueOf() is not available, ...