TypeScript Functions: Parameters, Return and Arrow Functions
November 6, 2026
Welcome to episode 10 of TypeScript from Zero, a series for complete beginners (no JavaScript needed). Welcome back to TypeScript from zero! Today: functions. A function is a named piece of code that we can run again and again. A new file called functions.ts. Every code block below is the code from the video, ready to copy; run each file to see the output.
- All episodes are in the TypeScript from Zero playlist.
- Versions used: Node.js 26.13.0, npm 11.20.0, TypeScript 7.0.2.
Setup
We start in the terminal and open the project in VS Code:
$ touch functions.ts1. Parameters
We write the word function, then a name, then the parameters in parentheses. Each parameter gets a type after a colon. The keyword return sends a value back to the caller. Here add takes two numbers and gives back their sum.
function add(a: number, b: number) {
return a + b;
}
console.log(add(2, 3));$ node functions.ts2. Scope
A function can also just do something, without giving anything back. This one prints a greeting. The variable message exists only inside the function, and outside nobody can see it. That is called scope.
function greet(who: string) {
const message = "Hello, " + who;
console.log(message);
}
greet("Mia");$ node functions.ts3. Arrow
There is a shorter way to write a function, called an arrow function. The parameter, then an arrow, then the result. Double takes a number and returns that number times two.
const double = (n: number) => n * 2;
console.log(double(4));$ node functions.ts4. Wrong call
Now a mistake: we call add with only one number. Node does not complain. The missing b is undefined, and two plus undefined is not a number. We see N a N.
console.log(add(2));$ node functions.ts5. tsc
tsc catches it: expected two arguments, but got one. The code is TS2554. TypeScript counts the arguments for us, before the program runs.
$ npx tsc --noEmit functions.ts6. Fix
We delete that line, and tsc is quiet again.
$ npx tsc --noEmit functions.tsRecap
Today: functions with typed parameters, return, a function that returns nothing, scope, and arrow functions. Next episode: a real project, with a T S config file.