# Strict mode

> How Kiln catches typos and missing data.

Strict mode is on by default. It turns a misspelt variable or a missing property into an error, instead of a blank space on the page that nobody notices.

page.kiln:

```kiln
<h1>{{ titel }}</h1>
```

Error:

```text
Unknown variable "titel" in page.kiln at line 1, column 8. Did you mean "title"?
```

## Optional data

When data may be missing, say so in the template. These never raise missing-variable or missing-property errors:

- `?.` returns null if the left side is null: `page?.author?.name`
- `??` uses a fallback: `page.subtitle ?? ""`
- `default` uses a fallback when the value is empty: `page.subtitle|default("")`
- `is defined` checks whether a value exists: `{% if page.subtitle is defined %}`

page.kiln:

```kiln
<h1>{{ page.title }}</h1>
<p>{{ page.subtitle ?? "No subtitle" }}</p>
```

Output:

```html
<h1>About</h1>
<p>No subtitle</p>
```

## Strict and lenient

| Situation | Strict | Lenient |
| --- | --- | --- |
| Unknown variable | Error | null |
| Missing property | Error | null |
| Property of null | Error | null |
| Required prop missing | Error | null |
| Prop not declared | Error | Ignored |
| Prop of the wrong type | Error | Not checked |
| Unknown filter, function, test or tag | Error | Error |
| Type errors, such as `"a" + 1` | Error | Error |

## Turning it off

Lenient mode treats missing data as null. Turn it on for the whole environment:

```ts
const kiln = createKiln({ loader, strict: false });
```

We recommend leaving strict mode on. Guarding optional data takes a few characters and catches real bugs.
