Syntax

TypeScript Optional Parameter Syntax

In TypeScript, optional parameter: makes a function parameter optional — function greet(name?: string) { ... }

Quick Answer

Syntax
function greet(name?: string) { ... }
TypeScriptSyntax

Optional Parameter

Code example
function greet(name?: string) { ... }

Makes a function parameter optional.

Learn More

How to optional parameter in TypeScript

  1. Open your TypeScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

TypeScript Optional Parameter Syntax

Use function greet(name?: string) { ... }.

Related Syntax References

Frequently asked questions

What is the TypeScript syntax for optional parameter?

Use this pattern: function greet(name?: string) { ... }

Can I copy this TypeScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this TypeScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify