Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to understand the meaning of function definition highlights in VS Code?

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.

Screenshot of the definition

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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[]): number mean?

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 values mean?

This is JSDoc syntax, and it refers to a function parameter.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading