Explore Library
Code QuizIntermediate

Non-null Assertion Hides Real Bug

The non-null operator silences the compiler but not the runtime error.

Codetypescript
function getLength(str?: string) {
  return str!.length;
}

console.log(getLength()); // throws at runtime

What is the bug in this code?