所以,据我检查,javascript 没有 XOR 运算符。
还有以下内容 -
if( ( foo && !bar ) || ( !foo && bar ) ) {
...
}
如果 foo 和 bar 是布尔值,这一点很清楚。但是 XOR 可以用来检查不同类型的表达式吗?例如,如果我想对照另一个值检查一个值,即 -
if (type === 'configuration' XOR type2 === 'setup') {
...
}
它会转变为类似的东西吗?
if ( (type === 'configuration' && type2 !== 'setup') || (type !== 'configuration' && type2 === 'setup' ) ) {
...
}
或者看起来会有所不同吗?
这给出了以下结果 -
type = 'configuration' && type2 = 'setup': false
type = 'configurations' && type2 …