Functions, lambdas, and execution flow
Functions are the processing machines we used to analyze input, digest information, and apply the necessary transformations to data that's provided either to transform the state of our application or to return an output that will be used to shape our application's business logic or user interactivity.
Functions in TypeScript are not that different from regular JavaScript, except for the fact that, just like everything else in TypeScript, they can be annotated with static types. Thus, they improve the compiler by providing it with the information it expects in their signature and the data type it aims to return, if any.
Annotating types in our functions
The following example showcases how a regular function
is annotated in TypeScript:
function sayHello(name: string): string { return 'Hello, ' + name; }
We can see two main differences from the usual...