Skip to main content

you can use optional variable by ? or if you have multiple optional variable by ..., example:

function details(Namename: string, country="CA", address?: string, ...hobbies: string) { // ... } 

In the above: Name: is a must country: has a default address: is an optional param hobbies: is an array of optional params 

  • name is required
  • country is required and has a default value
  • address is optional
  • hobbies is an array of optional params

you can use optional variable by ? or if you have multiple optional variable by ..., example:

function details(Name: string, country="CA", address?: string, ...hobbies: string) { // ... } 

In the above: Name: is a must country: has a default address: is an optional param hobbies: is an array of optional params

you can use optional variable by ? or if you have multiple optional variable by ..., example:

function details(name: string, country="CA", address?: string, ...hobbies: string) { // ... } 

In the above: 

  • name is required
  • country is required and has a default value
  • address is optional
  • hobbies is an array of optional params
Source Link
Hasan A Yousef
  • 25.3k
  • 29
  • 155
  • 254

you can use optional variable by ? or if you have multiple optional variable by ..., example:

function details(Name: string, country="CA", address?: string, ...hobbies: string) { // ... } 

In the above: Name: is a must country: has a default address: is an optional param hobbies: is an array of optional params