JavaScript: Is '!0' shorthand of Boolean 'true
JavaScript: Is '!0' shorthand of Boolean 'true'?
在将Google Analytics从异步版本更新为通用版本时,我看到了这条事件跟踪行,这是几年前别人写的。
_gaq.push(["_trackEvent", "Social Widget Share", "Shared to Facebook", "Share to Facebook via the Social Driver Widget", 0, !0])
我的理解是,最后一个元素是用"true"来指示非交互事件,否则它将被排除在数组之外。
我从来没有见过!0,我找不到任何迹象搜索在这里或其他地方在网络上!0是一个东西,当它涉及到布尔符号-或分析事件跟踪
是的,这是正确的,请看看下面的一些true
和false
的值
// False values
console.log('False values');
console.log(Boolean(false));
console.log(Boolean(0));
console.log(Boolean(!!0));
console.log(Boolean(!1));
console.log(Boolean(''));
console.log(Boolean(null));
console.log(Boolean(undefined));
// True values
console.log('True values');
console.log(Boolean('0')); // string variable
console.log(Boolean(!0));
console.log(Boolean(1));
console.log(Boolean(!!1));
console.log(Boolean(true));
是的,0总是为真,因为0为假,这是一种将真或1写成布尔值的方法
相关文章:
- HighChart : Usage of setData
- Difference between methods of defining JavaScript 'class
- 为什么我在下面的..of循环中得到意外令牌
- Appending the innerhtml of <th>
- Animation cuts off multiple lines of text in <p>
- javascript: functionname() instread of functionname()
- jQuery使用.of()删除事件处理程序时出现的问题
- Three.js issue creating meshes outside of loader's load(
- jquery in the middle of html
- JavaScript equivalent of C#'s DynamicObject?
- nodejs console.log of object
- value of jquery sortable
- Javascript imageData returns array of 0's
- 对于grunt构建中的(let.of)错误
- Opposite of jQuery's :eq()
- Implementation of jQuery 'animate' with Meteor
- 当调用.of()然后调用.on()时,Jquery是否可能将事件推迟
- Angularjs ng-options selected value of dropdownlist
- Java eqivalent method of “splice(a,b,..)“在 JavaScript 方法中
- JavaScript: Is '!0' shorthand of Boolean 'true