What are default parameter values in TypeScript?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for TypeScript development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
Default parameter values in TypeScript work the same as JavaScript's ES6 default parameters but with type inference. When you provide a default value, TypeScript automatically infers the parameter type from the default: function greet(name: string, greeting = "Hello"): string { return `\${greeting}, \${name}!`; } — greeting is inferred as string. The parameter becomes optional from the caller's perspective — you can omit it or pass undefined to use the default. You can combine with explicit types: function setPage(page: number = 1, limit: number = 10) { ... }. Default parameters can reference earlier parameters: function createRange(start: number, end: number = start + 10) { ... }. Unlike optional parameters (?), default parameters do not result in the type being widened to include undefined within the function body — they are guaranteed to have a value.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.