-2

Hey guys so i came across some unexpected behavior in js... and i have no idea why this happens... can someone explain to me? Thank you

campaign = {
  "ppmv_ref": "1324232571",
  "type": "value off",
  "title": "20% off the weed item",
  "percentage": "20",
  "product": "weed",
  "productId": "46482649",
  "quantity": "50",
  "startDate": "10/22/2018",
  "expirationDate": "10/23/2018",
  "couponFlag": "true",
  "active": "true"
}
condition = campaign.active === true;

console.log(campaign.active)// logs true
console.log(condition); // logs false
dbc
  • 104,963
  • 20
  • 228
  • 340
Monye David
  • 1
  • 1
  • 2

2 Answers2

1

Because you’re comparing a string to a Boolean .

campaign.active === true

This evaluate to false, you can wrap true with quotations and this will evaluate to true.

sagi
  • 40,026
  • 6
  • 59
  • 84
0

Because campaign.active store a string "true". So you should use: condition = campaign.active === "true"

protoproto
  • 2,081
  • 1
  • 13
  • 13