Bitweises UND-Zuweisung (&=)

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.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Der Operator für bitweise UND-Zuweisung (&=) führt ein bitweises UND auf den beiden Operanden aus und weist das Ergebnis dem linken Operanden zu.

Probieren Sie es aus

let a = 5; // 00000000000000000000000000000101
a &= 3; // 00000000000000000000000000000011

console.log(a); // 00000000000000000000000000000001
// Expected output: 1

Syntax

js
x &= y

Beschreibung

x &= y ist gleichbedeutend mit x = x & y, außer dass der Ausdruck x nur einmal ausgewertet wird.

Beispiele

Verwendung der bitweisen UND-Zuweisung

js
let a = 5;
// 5:     00000000000000000000000000000101
// 2:     00000000000000000000000000000010
a &= 2; // 0

let b = 5n;
b &= 2n; // 0n

Spezifikationen

Specification
ECMAScript® 2026 Language Specification
# sec-assignment-operators

Browser-Kompatibilität

Siehe auch