!0和!+0有啥区别啊
javascript吧
全部回复
仅看楼主
level 2
昨天在项目里看到这么个运算,很是好奇
json对象里有个属性是这么赋值的
xxx: !+sessionStorage.get(“xxx”)
各位大佬,我就想知道这个【!+变量】是怎么怎么算的?和取反有啥区别
2022年01月18日 02点01分 1
level 12
// 得到一个storage的值是字符串
// 他就想把字符串'0'转成数字类型0 在求反(逻辑非!)
alert(!'0'); // false
alert(!0); // true
// https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy
2022年01月18日 10点01分 2
1