Bitweises UND-Zuweisungsoperator (&=)

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.

Der bitweise UND-Zuweisungsoperator (&=) führt ein bitweises UND für die 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 des bitweisen UND-Zuweisungsoperators

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

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

Spezifikationen

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

Browser-Kompatibilität

BCD tables only load in the browser

Siehe auch