Explore Library
Code QuizIntermediate

Optional Chaining Yields Possibly Undefined

Comparing an optionally-chained value leaves it possibly undefined.

Codetypescript
function firstItem(arr?: string[]) {
  if (arr?.length > 0) {
    console.log(arr[0]);
  }
}

What is the bug in this code?