BeginnerCoder

Lesson 2 — Typed functions

Typed inputs and outputs

In TypeScript you type each parameter (the inputs) and the return type (the output), which goes after the parentheses. Then every call is checked: add("2", 3) becomes an error before you run anything, and the editor knows what the function gives back.

function shout(word: string): string {
  return word.toUpperCase() + "!";
}

Why it matters: functions are where values move around, so typing them catches most mix-ups at once.

Want it another way?
Task

Type a and b as numbers, make add return their sum, and print add(2, 3) → 5.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.