aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/division_assignment/index.html
blob: 25f93e997b44ecbd092972483b09030128f01cf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
title: Division assignment (/=)
slug: Web/JavaScript/Reference/Operators/Division_assignment
translation_of: Web/JavaScript/Reference/Operators/Division_assignment
---
<div>{{jsSidebar("Operators")}}</div>

<p>The division assignment operator (<code>/=</code>) divides a variable by the value of the right operand and assigns the result to the variable.</p>

<div>{{EmbedInteractiveExample("pages/js/expressions-division-assignment.html")}}</div>

<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox notranslate"><strong>Operator:</strong> x /= y
<strong>Meaning:</strong>  x  = x / y</pre>

<h2 id="Examples">Examples</h2>

<h3 id="Using_division_assignment">Using division assignment</h3>

<pre class="brush: js notranslate">// Assuming the following variable
//  bar = 5

bar /= 2     // 2.5
bar /= 'foo' // NaN
bar /= 0     // Infinity</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-assignment-operators', 'Assignment operators')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("javascript.operators.division_assignment")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment">Assignment operators in the JS guide</a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Division">Division operator</a></li>
</ul>

<p>
 <audio style="display: none;"></audio>
</p>