M Logo
๐Ÿ“ TypeScript from Zero ยท Part 10 of 50

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.

Setup

We start in the terminal and open the project in VS Code:

bash
$ touch functions.ts

1. 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.

ts
function add(a: number, b: number) {
  return a + b;
}
console.log(add(2, 3));
bash
$ node functions.ts

2. 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.

ts
function greet(who: string) {
  const message = "Hello, " + who;
  console.log(message);
}
greet("Mia");
bash
$ node functions.ts

3. 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.

ts
const double = (n: number) => n * 2;
console.log(double(4));
bash
$ node functions.ts

4. 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.

ts
console.log(add(2));
bash
$ node functions.ts

5. tsc

tsc catches it: expected two arguments, but got one. The code is TS2554. TypeScript counts the arguments for us, before the program runs.

bash
$ npx tsc --noEmit functions.ts

6. Fix

We delete that line, and tsc is quiet again.

bash
$ npx tsc --noEmit functions.ts

Recap

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.

ยฉ 2026 All Rights Reserved By Mahmudul Alam