Functions
A function is a recipe with steps.
You give it inputs. It gives you an output.
TypeScript puts name tags on those inputs and outputs.
That way callers know what to pass and what comes back.
Parameter and return types
A parameter is an input blank.
Write a type after each parameter.
Write a return type after the parentheses.
Return type means the name tag on what comes out.
void for no return value
void means the function does not give a useful value back.
It may still do work, like printing.
Use void when the side effect is the point.
A side effect is a change outside the return value.
Function type expressions
You can write the whole function shape as a type.
That is handy for variables that hold functions.
Or for callbacks.
A callback is a function you hand to another function.
Inference on returns
TypeScript can often guess the return type.
Writing it still helps readers and catches mistakes.
If you return the wrong thing, the written type catches you.
Arrow functions
Arrow functions use the => form.
Types work the same way.
They are common for short helpers and callbacks.
Type every input. Type the output when it helps. Callers will thank you.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.