Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Division assignment (/=)

The /= operator divides the current value of a variable or property by the right operand and stores the result in the same location. It supports Number and BigInt, but does not allow those types to be mixed.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

target /= divisor

The expression target /= divisor reads the target's value, performs division, and writes the result back. The whole expression evaluates to the assigned result. For a simple variable, x /= y behaves like x = x / y, but the target is evaluated only once: in values[index++] /= 4, index increases only once.

Operands undergo numeric conversion; for example, let x = "12"; x /= 3; stores the number 4 in x. After conversion, both operands must be Number values or both must be BigInt values; combining 12n and 3 throws a TypeError.

For Number, the result can have a fractional part and is subject to floating-point precision limits. Dividing a finite nonzero number by zero produces Infinity or -Infinity, while 0 / 0 produces NaN. For BigInt, the fractional part is truncated toward zero: -15n / 2n produces -7n. Division by 0n throws a RangeError.

The target must allow assignment. Attempting to change a variable declared with const throws a TypeError; a property of an object held in const can still be writable. If division itself throws, the operator does not write a result.

Examples

let amount = 15;
const result = (amount /= 2);
console.log(amount, result);

let whole = -15n;
whole /= 2n;
console.log(String(whole));

const values = [20];
let index = 0;
values[index++] /= 4;
console.log(values[0], index);

Result

7.5 7.5
-7
5 1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources