Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. JavaScript
  3. JavaScript リファレンス
  4. 式と演算子
  5. 除算代入演算子 (/=)

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

除算代入演算子 (/=)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

除算代入演算子 (/=) は、2 つのオペランドで除算を行い、結果を左オペランドに代入します。

試してみましょう

let a = 3;a /= 2;console.log(a);// 予想される結果: 1.5a /= 0;console.log(a);// 予想される結果: Infinitya /= "hello";console.log(a);// 予想される結果: NaN

構文

js
x /= y

解説

x /= yx = x / y と同等ですが、式x が一度だけ評価される点が異なります。

除算代入の使用

js
let bar = 5;bar /= 2; // 2.5bar /= 2; // 1.25bar /= 0; // Infinity

その他の長整数以外の値は数値に変換されます。

js
let bar = 5;bar /= "2"; // 2.5bar /= "foo"; // NaN

長整数を使用した除算代入

js
let foo = 3n;foo /= 2n; // 1nfoo /= 2n; // 0nfoo /= 0n; // RangeError: BigInt division by zerofoo /= 1; // TypeError: Cannot mix BigInt and other types, use explicit conversions

仕様書

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

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp