回答:
これはビット単位のorです。
ビット演算0.5は整数に対してのみ意味があるため、切り捨てられます。
0 | xはx、すべてのxです。
parseInt()
ビット比較はとてもシンプルなので、ほとんど理解できません;)この「ニブル」をチェックしてください
8 4 2 1
-------
0 1 1 0 = 6 (4 + 2)
1 0 1 0 = 10 (8 + 2)
=======
1 1 1 0 = 14 (8 + 4 + 2)
ビットごとのOR演算6と10は14を与えます:
alert(6 | 10); // should show 14
ひどく混乱しています!
alert(true | false) //yields 1; alert(true | true) //yields 1; alert(false | true) //yields 1; alert(false | false) //yields 0
この例が役立ちます。
var testPipe = function(input) {
console.log('input => ' + input);
console.log('single pipe | => ' + (input | 'fallback'));
console.log('double pipe || => ' + (input || 'fallback'));
console.log('-------------------------');
};
testPipe();
testPipe('something');
testPipe(50);
testPipe(0);
testPipe(-1);
testPipe(true);
testPipe(false);