Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
How to convert NaN value to 0 inside app.post in .js file

In below code question1 value is coming as NaN. I want to convert it to 0 but I am not able to do it using parseInt. How can I do this?

app.post('/auth/total',function(req,res){
    console.log(req.body);
    const {  question1, question2, question3, question4} = req.body;
    let total1 = parseInt(question1) + parseInt(question2) 
    let total2 = parseInt(question3) + parseInt(question4) 
    
    //some code to insert data in db and render the view 

});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can do this:

let total1 = (parseInt(question1) || 0) + (parseInt(question2) || 0)

this will convert any falsy value to 0

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!