TypeScript · Junior · Question 12 of 75
How do you type a function that takes a string and returns a number?
- ✓Correct answer:
(s: string) => number - 2
(string) => number - 3
function(s): string -> number
Explanation
In a function type, parameter names are required: (s: string) => number. (string) => number means a parameter named string of type any. A function declaration: function len(s: string): number { ... }.