CodingNeed.

1 · Write contracts · 8 MIN

Type a function

Functions turn inputs into outputs.

Parameter and return annotations make a function contract explicit. TypeScript still runs as JavaScript after compilation. Runtime tests and compile-time checking serve different purposes.

A small machine takes an ingredient, performs one operation, and gives you a result.

Read the example

function double(n: number): number { return n * 2; }
console.log(double(4));
Check the expected output
8

Your challenge

Return the larger of input.a and input.b. Equal values should return that value.

Common trap

Logging an answer does not return it to a caller.

Next lesson: Describe an object