Avatar ·

What is the question mark used for in TypeScript function parameters?

Hello everyone! I recently started learning TypeScript and came across a strange construct in function parameters. I see that sometimes a question mark is placed before the colon and the parameter type. For example: ```typescript function greet(name?: string) { return `Hello, ${name || 'Guest'}!`; } ``` I understand that `: string` means the parameter must be a string. But what does `?` do before it? I tried calling the function with and without the parameter — it works both ways. But if I remove the question mark, TypeScript starts complaining when I call `greet()` without an argument. What exactly does this question mark mean? Is it a JavaScript feature or only TypeScript? And is there a difference between `name?: string` and `name: string | undefined`? I would be grateful for a detailed explanation.