Which fix removes the bug?
const el = document.getElementById('name');
el.value = 'Sam';
- Null-check
elbefore using - Rename
elto avoid a clash - Move the lookup into a class
- Read
.valuebefore writing
getElementById returns HTMLElement | null, so el may be null at runtime.
Play Problem Solving ▸