How to remove or simply substitute Nan with 0?

I have 2 inputs.

When I put 2 in the n1 input, the second input says 4.

But if I don’t put anything in the first (n1), the second inpout (n2) says NaN.

How remove this NaN?

<td><input type="number" value=0 id="n1" oninput="test()"/> <br/><br/></td>


<td><input type="text" value=0 id="result" readonly/><br><br></td>
function test () {
  var n1 = parseFloat(document.getElementById('n1').value);

  var oper = document.getElementById('selector1').value;
  var oper2 = document.getElementById('selector2').value;

  if (oper === 'm' && oper2 === 's') {
    document.getElementById('result').value = n1 * 60;


Change this line:

var n1 = parseFloat(document.getElementById('n1').value);

to this one:

var n1 = parseFloat(document.getElementById('n1').value) || 0;

This will give n1 a value of 0 if you leave its input field blank.