> For the complete documentation index, see [llms.txt](https://radoslaw-medryk.gitbook.io/verifica/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://radoslaw-medryk.gitbook.io/verifica/predicates/operations-on-predicates/optional.md).

# optional

```
function optional(predicate): Predicate
```

This function takes a `Predicate` as an argument and returns `Predicate` that matches on the same conditions as the original one, but allows `null` and `undefined` values as well. This predicate doesn't consider missing (i.e. not existing) values as valid.

## Examples:

First, let's define an example `value` that we want to verify and wrap it with `asVerificable():`

```typescript
const { asVerificable, optional, isString, isValid } = require("verifica");

const value = null;
const verificable = asVerificable(value);
```

Next, let's use the `optional()` function to create `Predicate` that allows optional values:

```typescript
const isOptionalString = optional(isString);
```

Now, let's test the new `Predicate` compared to the original one:

```typescript
isValid(verificable, isString); // false

isValid(verificable, isOptionalString); // true
```
