Typeof gives me'"number" but console.log gives me "NAN"(is this possible)

store = {

    bags : { 
        inventory : 30,
        cost : 12.99

    },
    pen : {
       inventory : 30,
       cost : 34.23
    }
};
const buy = (x,y,)=>{
  
    return new Promise((resolve, reject)=>{
      
        if(x ==='bags'  && y >= 1 && y< 30 ){
            resolve(parseInt((y*store.bags.cost)));
        }else { reject ('out of order');}; 
    });  
};

const buy1 = (x,y,)=>{
  
    return new Promise((resolve, reject)=>{
      
        if(x ==='pen'  && y >= 1 && y< 30 ){
            resolve(parseInt((y*store.pen.cost)));
        }else { reject ('out of order');}; 
    });  
};
const totalBag = [];
const totalPen = [];
parseInt(totalBag.push(buy('bags',12)));
parseInt((totalPen.push(buy1('pen',12))));

totalsum = parseInt(totalBag)+ parseInt(totalPen);
console.log(typeof totalsum) // output number 
console.log(totalsum);      // output NaN

I could be mistaken, as I’m a bit rusty with JavaScript, but I believe that NaN actually has a type of number because that’s part of the spec.

:slight_smile:

1 Like
// this code below gives me integer but my previous post gives me NAN I //can't see what is wrong 
store= store = {

    bags : { 
        inventory : 30,
        cost : 12.99

    },
    pen : {
       inventory : 30,
       cost : 34.23
    }
};

const buy = (x,y)=>{
  
        if(x ==='bags'  && y >= 1 && y< 30 ){
            return (parseInt(y*store.bags.cost));
        }else { ('out of order');};  
};

const buy1 = (x1,y1)=>{
  
    if(x1 ==='pen'  && y1 >= 1 && y1< 30 ){
        return (parseInt(y1*store.pen.cost));
    }else { ('out of order');};  
};
const totalBag = [];
const totalPen = [];
parseInt(totalBag.push(buy('bags',12)));
parseInt((totalPen.push(buy1('pen',12))));

 const sumtotal = parseInt(totalBag) + parseInt(totalPen);

console.log(typeof sumtotal);  // output : number 
console.log(sumtotal);             // output:  565