背景: 0 == '0' 返回ture
后台新增一个开关,字段名为 switch,因为只有在特定情况下才需要去接口取值,因此我新增一个变量 _switch = 0.
如果需要去接口取值,则_switch = data.switch。
接下来的逻辑便是:
if(_switch) {逻辑1
}else{逻辑2
}
咋一看是不是没什么问题..
万万没想到,接口返回的switch值为string类型的0即"0"。
我 *&)&@¥#@¥#&¥......
于是只要触发接口,永远进逻辑1。
我曾经很天真,因为 0 == '0' 所以 if(0) 和 if('0') 是一样的,但if对字符串的判断,判断的是长度而不是值。。
❤️ 稀碎