⊗jstsPmFnPQ 48 of 55 menu

Number of function parameters in TypeScript

In TypeScript, when a function is called, exactly as many values ​​must be passed to it as there are parameters defined in it.

Let's look at an example. Let's say we have a function that takes the user's first and last name as a parameter and returns them as a string:

function func(first: string, last: string) { return first + ' ' + last; }

Let's call our function with a different number of parameters:

func('john'); // error, not enough parameters func('john', 'smit', 'xx'); // error, too many parameters func('john', 'smit'); // works

The following function is given:

function func(a: number, b: number) { return a + b; }

Tell what the result of each of the following function calls will be:

func(1); func(1, 2, 3); func(1, 2);
enru