Q26. What is the difference between optional and nullable properties?

An optional property may be absent. A nullable property explicitly allows null in its value type. With strict null checking, these are distinct concepts: name?: string and name: string | null express different contracts.

An API may omit an optional field entirely, while a required nullable field must exist but may contain null.

Note

Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.

TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";
💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
  • Explain the concept in your own words.
  • Know the practical trade-off and its limits.
  • Use a small example to demonstrate the idea.
Knowledge Check

Which type requires the property to exist but permits null?