Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

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

leftOperand / rightOperand

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

// 1. Standard number division
const floatResult: number = 10 / 4;      // Evaluates to 2.5
const zeroDiv: number = 10 / 0;          // Evaluates to Infinity
const zeroDivNeg: number = -10 / 0;      // Evaluates to -Infinity
const nanResult: number = 0 / 0;         // Evaluates to NaN

// 2. BigInt division (requires 'n' suffix)
const bigIntResult: bigint = 10n / 4n;   // Evaluates to 2n (truncated towards zero)

// 3. Compile-time Type Errors
const mixedError = 10 / 2n;              // Error: Operator '/' cannot be applied to types 'number' and 'bigint'.
const stringError = "10" / 2;            // Error: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

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.
let x: number = 20;
x /= 4;  // Equivalent to: x = x / 4; Evaluates to 5

let y: bigint = 10n;
y /= 3n; // Equivalent to: y = y / 3n; Evaluates to 3n
Master TypeScript with Deep Grasping Methodology!Learn More