$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #150

Which fix removes the bug?

const el = document.getElementById('name');
el.value = 'Sam';
  1. Null-check el before using
  2. Rename el to avoid a clash
  3. Move the lookup into a class
  4. Read .value before writing
getElementById returns HTMLElement | null, so el may be null at runtime.
Play Problem Solving ▸