Explore Library
Code QuizIntermediate

Wrong Null Check Misses Undefined

A check against null fails to narrow out undefined.

Codetypescript
function shout(name: string | undefined) {
  if (name !== null) {
    console.log(name.toUpperCase());
  }
}

shout(undefined); // runtime crash

What is the bug in this code?