답변:
이것은 비트 단위 또는 입니다.
비트 단위 연산은 정수에만 의미 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);