按位异或赋值 (^=)
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
按位异或赋值操作符 (^=
) 使用二进制表示操作数,进行一次按位异或操作并赋值。
尝试一下
语法
Operator: x ^= y Meaning: x = x ^ y
示例
使用按位异或赋值
js
let a = 5; // 00000000000000000000000000000101
a ^= 3; // 00000000000000000000000000000011
console.log(a); // 00000000000000000000000000000110
// 6
let b = 5; // 00000000000000000000000000000101
b ^= 0; // 00000000000000000000000000000000
console.log(b); // 00000000000000000000000000000101
// 5
规范
Specification |
---|
ECMAScript Language Specification # sec-assignment-operators |
浏览器兼容性
BCD tables only load in the browser