Functions group related steps into one reusable unit. This makes code easier to test, reuse, and understand.
function greetUser(name: string): string {
return `Hello, ${name}!`;
}
const message = greetUser("Ava");
console.log(message);
function calculateTax(amount: number): number {
return amount * 0.08;
}
function calculateTotal(amount: number): number {
return amount + calculateTax(amount);
}
console.log(calculateTotal(50));