var
type = 'foo',
type2 = 'bar',
result = 0;
type == 'foo' && result++;
console.log(result); // 1
!type == 'foo' || result++;
console.log(result); // 2
type == 'foo' && type2 == 'bar' && result++;
console.log(result); //3
type == 'foo' && type2 == 'bar' && result == 3 && (result=0); //parentheses avoid "invalid assignment left-hand side" error
console.log(result); //0
type == 'OOF' || result++; //equivalent: type != 'OOF' && result++;
console.log(result); //1
в каком порядке это работает?JS логические операторы
type == 'foo' && result++;
!type == 'foo' || result++;
полный текст статьи (https://github.com/shichuan/javascript-patterns/blob/master/general-patterns/conditionals.html)
Если 'type == 'foo'' истинно, тогда будет увеличиваться только' result ++ '... В случае' '' независимо от первого условия выполняется 'result' будет увеличиваться ... – Rayon