liveBook · Manning

Comparison

As explained in Math for Web Design

A comparison operator is an operator that specifies the relationship to test between two values.

A comparison operator tests the relationship between two values and produces a condition that can guide layout, styling, validation, or animation logic. Common tests include greater than (>), less than (<), equality, inequality, and inclusive bounds (>=, <=). section 1.4.6

CSS usually expresses comparisons implicitly: min-width means greater than or equal to, while max-width means less than or equal to. JavaScript writes the operator explicitly. section 1.4.6 section 6.2.3

Use comparisons carefully when values come from different sources:

  • Prefer strict equality (===) and strict inequality (!==); they require both the type and value to match. section 2.1.3
  • Treat loose equality (==) and loose inequality (!=) cautiously because JavaScript may coerce one value to another type. section 2.1.3
  • Convert numeric input before comparing dimensions, positions, or animation timings. section 2.1.3

Responsive breakpoint

A two-column layout can activate when the viewport reaches 768 pixels: CSS uses @media (min-width: 768px), while JavaScript can test window.innerWidth >= 768. Both express the same inclusive lower-bound comparison. section 1.4.6 section 6.2.3

Type-sensitive input comparison

With input = "100" and width = 100, input == width returns true because JavaScript coerces the string, but input === width returns false. Convert first with Number(input), then compare strict values. section 2.1.3

Table 2.3 JavaScript comparison operators

Operator

Name

Example

Result

==

Equal (loose)

"5" == 5

true

===

Equal (strict)

"5" === 5

false

!=

Not equal (loose)

"5" != 5

false

!==

Not equal (strict)

"5" !== 5

true

<

Less than

3 < 5

true

>

Greater than

4 > 5

false

<=

Less than or equal

4 <= 4

true

>=

Greater than or equal

5 >= 6

false

Use the operator table to compare loose and strict equality with ordering operators and their results. section 2.1.3

How Math for Web Design covers it

How deep it goes
Explains operator meanings, CSS shorthand, JavaScript coercion, strict equality, and numeric conversion through practical examples.
Examples
Uses responsive breakpoints, clamped font sizes, input selectors, password length checks, and string-to-number comparisons.
What it assumes
Assumes basic CSS and JavaScript syntax while teaching inequality symbols, equality modes, and type conversion.
What you can do after
Apply comparisons via CSS and JavaScript to make predictable layout, validation, and animation decisions.
How it connects
Connects comparison operators with JavaScript type coercion, CSS media queries, responsive design, DOM input, and animation.

Also explained in

Compare how 8 books explain comparison →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.