Files
it-know-how/typescript/bits/01-function-declaration-syntax.md
T
2026-03-27 12:58:01 +01:00

635 B
Executable File

Function Declaration Syntax in TypeScript

A function declaration defines a reusable block of logic with typed inputs and output.

Basic Shape

function greet(name: string): string {
	return `Hello, ${name}`;
}

Parts Explained

  • function: keyword to declare a function.
  • greet: function name.
  • (name: string): parameter list with a type annotation.
  • : string: return type annotation.
  • { ... }: function body.

Python Comparison

def greet(name: str) -> str:
		return f"Hello, {name}"

TypeScript puts type annotations after variable names as name: string, similar to Python type hints.