typescript example

Typed sum in TypeScript

Add two numbers with parameter and return types. Run TypeScript online without a local tsc setup.

Type annotations document the contract: both arguments are numbers, and the function returns a number.

Code Arena strips types before Node runs the file. If you pass the wrong kind of value, you may still see a runtime issue — types help you, they do not replace Output.

function sum(a: number, b: number): number {
  return a + b;
}

console.log(sum(3, 4));