1

When I am trying to add two numbers, I am able to get NaN. If anyone has any advice, any help would be greatly appreciated.

This is my Code:-

  var sum = parseInt(label.labellength, 10) + parseInt(label.labely, 10);
  console.log("Sum of FrontRight is " + sum );

Output is:-NaN

I tried as following :

Using Number

  var sum=Number(label.labellength) + Number(label.labely);

Output is:-NaN

Bikram
  • 33
  • 4

1 Answers1

0

The same issue came to me , try to use || operator and return it, it did the same and it worked for me...

const [contextOverHr,setContextOverHr=useState("")
return (
  {Object.values(workHour).reduce((pre,total) => {
                  let totalNum = pre + total.OverHour
                  setContextOverHr (totalNum)
                  return totalNum || 0
                },0)
  }
)
rMonteiro
  • 1,371
  • 1
  • 14
  • 37
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 14 '22 at 18:42