Skip to main content
The / (division) operator is a binary arithmetic operator that calculates the quotient of its left operand (dividend) divided by its right operand (divisor). In TypeScript, the compiler strictly enforces type constraints on this operator, requiring both operands to be of compatible numeric types (number or bigint) and preventing the implicit type coercion of non-numeric types found in standard JavaScript.

Syntax

Type Resolution and Behavior

TypeScript applies specific type-checking rules and runtime behaviors depending on the operand types:
  • number / number: Returns a number. Because TypeScript uses the IEEE 754 double-precision 64-bit floating-point format, the result includes fractional components. Division by zero does not throw a runtime error; it evaluates to Infinity, -Infinity, or NaN.
  • bigint / bigint: Returns a bigint. The result is always truncated towards zero (fractional digits are discarded). Division by zero throws a runtime RangeError.
  • Mixed Types (number / bigint): Results in a compile-time TypeError. TypeScript does not implicitly convert between number and bigint during arithmetic operations.
  • Non-Numeric Types: Results in a compile-time TypeError. Unlike JavaScript, which attempts to coerce strings or booleans into numbers, TypeScript statically rejects these operations.

Syntax Visualization

Compound Assignment (/=)

The division operator can be combined with the assignment operator to divide a variable by a value and assign the quotient back to the variable. The strict type-checking rules of the standard division operator apply identically to the compound assignment.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More