liveBook · Manning

Optional parameter

Also called optional argument

An optional parameter is a function or method parameter that a caller may omit, typically because a default value or other defined behavior applies when it is absent.

How 4 Manning books explain it

The Well-Grounded Rubyist, Fourth Edition

An optional parameter is a method parameter whose value can be omitted because a default value is specified.

How it is used
Makes Ruby method calls flexible when callers need not supply every positional or keyword value.
How deep it goes
Works through defaults, starred arrays, mixed-parameter binding, and invalid ordering; treats keyword arguments separately.
Examples
Compares method calls that use defaults, override them, fill catch-all arrays, or fail for too few arguments.
What you can do after
Build it from scratch using valid Ruby signatures with optional positional or keyword parameters, and predict argument assignments.

Read how The Well-Grounded Rubyist, Fourth Edition explains optional parameter →

Essential TypeScript 5, Third Edition

An optional parameter is a function parameter that may be omitted by the caller and is denoted with a question mark in TypeScript.

How it is used
Allows callers to omit an argument when a function can operate without its value.
How deep it goes
Explains declaration syntax, required-parameter ordering, omitted values, and the need for a fallback; does not explore compiler internals.
Examples
Uses a tax calculation called with one or two arguments, plus a rejected call with three.
What you can do after
Apply it in TypeScript functions to permit omitted arguments while handling the resulting `undefined` value.

Read how Essential TypeScript 5, Third Edition explains optional parameter →

ASP.NET Core in Action, 3e

An optional parameter is a handler or method parameter that may receive no corresponding input and instead accept a null or default value.

How it is used
Handles missing route, query, or body input without preventing a minimal API handler from running.
How deep it goes
Explains nullable syntax and runtime null behavior, while treating default parameter values as a separate feature.
Examples
Demonstrates /stock/{id?} with int?, a nullable Product body, and contrasting required-parameter failure behavior.
What you can do after
Apply optional arguments via ASP.NET Core minimal APIs to accept missing values and handle null explicitly.

Read how ASP.NET Core in Action, 3e explains optional parameter →

Pro Angular 16

An optional parameter is a function parameter that may be omitted when the function is called.

How it is used
Allows callers to omit selected arguments, especially when constructing product models whose properties may come from HTML forms.
How deep it goes
Defines the `?` syntax, omitted-value behavior, inferred `undefined`, and distinction from a required `string | undefined` parameter.
Examples
Uses a string-printing function with a fallback and Product constructors with omitted model fields.
What you can do after
Apply optional parameters to let calls omit arguments or create partially populated Product objects.

Read how Pro Angular 16 explains optional parameter →

Also covered in

What to know first

Related concepts

Questions about optional parameter

What is optional parameter?

An optional parameter is a function or method parameter that a caller may omit, typically because a default value or other defined behavior applies when it is absent.

Which Manning books explain optional parameter?

The Well-Grounded Rubyist, Fourth Edition, Essential TypeScript 5, Third Edition, ASP.NET Core in Action, 3e and Pro Angular 16.

What should I know before learning optional parameter?

Manning books that teach optional parameter usually introduce function, function argument, JavaScript and function overloading first.

What is the difference between optional parameter and default value?

An optional parameter is a function or method parameter that a caller may omit, typically because a default value or other defined behavior applies when it is absent. A default value is a predefined value automatically applied when no explicit value is supplied or specified.

What kinds of optional parameter are there?

Kinds of optional parameter include array argument.

What is optional parameter a kind of?

Optional parameter is a kind of parameter. A parameter is a value or named input that specifies or influences the behavior, computation, or output of a function, model, or system.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.