635 B
Executable File
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.