Just use "?", so if there's value it will return otherwise you will not get null value error.
const sodas = Number(document.querySelector('input[name = soda]:checked')?.value); console.log(sodas);