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.Please help me if i can convert NaN value to 0
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
});
>Solution :
you can do this:
let total1 = (parseInt(question1) || 0) + (parseInt(question2) || 0)
this will convert any falsy value to 0