Skip to content

Latest commit

 

History

History
80 lines (73 loc) · 2.79 KB

default-value.md

File metadata and controls

80 lines (73 loc) · 2.79 KB

Default Value

A default value is the value that's assigned to a function parameter if the caller does not pass in that parameter.

For example:

function doSomething(
    input: any,
    { onError = THROW_THE_ERROR }: OnErrorOptions = {}
) { ... }

// when we do this, `onError` uses the default value
// of `THROW_THE_ERROR`
doSomething(input);

// when we do this, `onError` uses our arrow function
// instead of the default value
doSomething(input, { onError: (e) => { logger.logError(e); throw e; }});

Not every programming language supports default values. Golang is a noteable language that does not.