伙计们,所以我在js中遇到了一些意外行为...我不知道为什么会这样...有人可以向我解释吗?谢谢
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
答案 0 :(得分:1)
因为您要将字符串与布尔值进行比较。
+------------------------+
| 16 Years and 1 Months. |
+------------------------+
此评估为false,您可以用引号将true换行,这将评估为true。
答案 1 :(得分:0)
因为campaign.active === true
存储字符串“ true”。因此,您应该使用:
campaign.active