jeudi 28 juin 2018

Node js if condition is not working properly

I want to initialize global variable with body of json object. But in my code if is not being executed instead of if, else part of code executes, if console.log typeof ticker I get undefined. What appears to be the problem.

var ticker ; 
request ({
      method : 'POST',
      url    :  'xyz'
 },(err,res,body)=>{

  if (typeof ticker === undefined) {
    ticker = body ; 
     }
    else {

      console.log(ticker) 
   }

Aucun commentaire:

Enregistrer un commentaire