Explore Library
Code QuizIntermediate

Reassignment Resets Narrowing

A variable reassigned to a number is still used as a string.

Codetypescript
function demo() {
  let x: string | number;
  x = "hello";
  console.log(x.toUpperCase());
  x = 42;
  console.log(x.toUpperCase());
}

What is the bug in this code?