TypeScript can be named or anonymous. This allows you to choose the most convenient approach for developing your application, whether it is building a list of functions in the API, or nesting one function within another. ...
Each function has a type, just like regular variables. A function type actually represents a combination of parameter types and return types. For example, take the following function:
It is of type
(x: number, y: number) => number;, that is, it takes two number parameters and returns a value of type number. Parameter names in a function type do not have to match the names of a specific function. The return type is preceded by an equal sign with an arrow.
And just like defining variables of a specific type, you can define variables that have a function type:
That is, the variable
op represents any function that takes two numbers and returns a number. For example:
Here, at the beginning, the variable
op points to the function
sum.And accordingly, calling op (2, 4) will actually represent a call to sum (2, 4). And then
op points to a function
Thanks goes to these wonderful people (emoji key):
🐛 🎨 🖋
🖋 🐛 🎨