How to check if input is empty in JavaScript?

To check if input is empty in JavaScript, do this: input.value === ''.

So if this is your input:

<input id="my-input">

Then you can check whether it is empty with this JavaScript:

if (document.getElementById('my-input').value === '') {
  console.log('Input is empty!');
} else {
  console.log('Input is NOT empty!');
}

And you can check this while the user types into the input with this JavaScript:

document.getElementById('my-input').addEventListener('input', event => {
  if (event.target.value === '') {
    console.log('Input is empty!');
  } else {
    console.log('Input is NOT empty!');
  }
});