---
title: "Equality and boolean discipline"
image: "https://hem.run/social/hem.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://hem.run/llms.txt
> Use this file to discover all available pages before exploring further.

# Equality and boolean discipline

`==` in Hem **is** strict equality: it compiles to `===`, and coercing equality is not expressible. Beyond that, Hem removes truthiness entirely: conditions, `!`, `&&`, and `||` require `boolean` operands.

<!-- This is the refused form the following diagnostic teaches. -->
```hem
if items.length { flush(items) }
```

```
error[HEM2002] dashboard.hem:8:4
  |
8 | if items.length {
  |    ^^^^^^^^^^^^ This condition has type `number`, not `boolean`. Compare it explicitly before branching.
```

Write the comparison you mean: `if items.length > 0 { flush(items) }`.

Defaulting belongs to `??`, absence checks to `== None` (§6). Each of JavaScript's truthiness jobs gets an explicit, typed spelling.

`+` gets the same discipline: it is arithmetic only. Both operands must be `number`, or both `bigint`: never a string, and never a mix. String concatenation has exactly one spelling in Hem, a template literal:

<!-- This is the refused form the following diagnostic teaches. -->
```hem
let name = "Ada"
let greeting = "Hello, " + name
```

```
error[HEM2021] app.hem:2:16
  |
2 | let greeting = "Hello, " + name
  |                ^^^^^^^^^^^^^^^^ `+` cannot combine string-ish operands; write `${"Hello, "}${name}` as a template literal instead.
```

Write `` `Hello, ${name}` `` instead. `+=` follows the same rule. Unary `+` narrows further: it is a coercion in disguise, so it requires an already-`number` operand; write `Number(x)` rather than `+x` on anything that isn't already a number.

Source: https://hem.run/tour/equality-and-boolean-discipline/index.mdx
