Function types

Typed parameters and return.

Typed parameters and a return type. Arrow functions keep the types.

Goal

Log a typed total.

function total(units: number, price: number): number {
  return units * price;
}
console.log(total(12, 40));
type Totaller = (units: number, price: number) => number;
const total: Totaller = (u, p) => u * p;
console.log(total(8, 40));
function greet(city: string = "Nairobi"): string {
  return "Kiosk in " + city;
}
console.log(greet());
console.log(greet("Eldoret"));
function logCity(city: string): void {
  console.log(city);
}
logCity("Nakuru");