jeudi 25 avril 2019

Use Ternary operator instead of if..else in javascript

Instead of if...else statement how to do using ternary operation or any alternative way to simplify code in javascript

if(req.query.pr=="trans"){
    util.transUrl(req.originalUrl).then(param => {
      res.redirect(param);
    })
  }
  else if(req.query.pr=="inst"){
    util.instaUrl(req.originalUrl).then(param => {
      res.redirect(param);
    })
  }
  else{
    res.status(400).send("Contact the editor of the originating page.")
  }

Aucun commentaire:

Enregistrer un commentaire