Q04. What does strictNullChecks do?

It treats null and undefined as distinct types rather than allowing them wherever a value of another type is expected. Code must narrow nullable values or provide a fallback before using them as non-null values.

With strict null checks, string | undefined is not interchangeable with string; guard it or use a deliberate default.

Note

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

Narrow nullish values
function upper(value: string | undefined) {
  return value === undefined ? "" : value.toUpperCase();
}
💡 The conditional narrows value to string in the final branch.
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

How should code handle a possibly undefined string before calling `toUpperCase()`?