剰余代入 (%=)

剰余代入演算子 (%=) は、変数を右辺のオペランドの値で除算し、剰余を変数に代入します。

試してみましょう

構文

js
x %= y; // x = x % y

剰余代入の使用

js
// 以下の変数を想定
//  bar = 5

bar %= 2; // 1
bar %= "foo"; // NaN
bar %= 0; // NaN

仕様書

Specification
ECMAScript Language Specification
# sec-assignment-operators

ブラウザーの互換性

BCD tables only load in the browser

関連情報