Let’s suppose I wrote the following code snipped in VSC:
let a = [1,2,3,4,5];
console.log(Math.max(...a))
If you hover over max, VSC gives you it’s definition as:
(method) Math.max(...values: number[]): number
Returns the larger of a set of supplied numeric expressions.
@param values — Numeric expressions to be evaluated.
What does (...values: number[]): number mean? Does that mean that it takes in an array and stores it as an array called number[] internally? Also, what does @param values mean?
>Solution :
What does
(...values: number[]): numbermean?
This uses rest parameter syntax, and just means that all of the parameters are of the same type: number. The return type of the function is also number.
This syntax value: type comes from TypeScript.
Does that mean that it takes in an array and stores it as an array called
number[]internally?
If you were to implement Math.max yourself using this signature, then yes, all of the arguments passed to the function would be stored in a variable called values, which would be an array of numbers.
Also, what does
@param valuesmean?
This is JSDoc syntax, and it refers to a function parameter.