Skip to main content
The multiplication operator (*) is a binary arithmetic operator that calculates the product of its two operands. In JavaScript, it operates on both Number (adhering to IEEE 754 double-precision floating-point arithmetic) and BigInt types.

Type Coercion and Evaluation

If an operand is not a primitive Number or BigInt, JavaScript implicitly coerces it using the abstract ToNumeric operation before executing the multiplication. The ToNumeric operation coerces the value to a Numeric type, which can be either a Number or a BigInt, depending on the operand’s primitive representation.
  • Objects: JavaScript attempts to convert the object to a primitive value by calling its valueOf() method, followed by toString(). The resulting primitive is then coerced to a Numeric type. If the object resolves to a BigInt primitive, it evaluates as a BigInt.
  • Booleans: true coerces to 1, false coerces to 0.
  • Strings: Parsed as numeric values. Empty strings ("") coerce to 0. Unparseable strings coerce to NaN.
  • Null/Undefined: null coerces to 0. undefined coerces to NaN.

IEEE 754 Floating-Point Precision Loss

Because JavaScript Number types are represented as 64-bit floating-point values, the * operator is subject to floating-point precision loss. Operations involving fractional numbers cannot always be represented exactly in binary, leading to rounding errors during multiplication.

IEEE 754 Edge Cases

The * operator follows specific rules for special numeric values (NaN, Infinity, -Infinity, and -0):
  • NaN: If either operand evaluates to NaN, the result is always NaN.
  • Infinity: Multiplying Infinity by a non-zero number results in Infinity (or -Infinity depending on the sign).
  • Infinity and Zero: Multiplying Infinity (or -Infinity) by 0 (or -0) evaluates to NaN.
  • Signed Zeros: Multiplying two numbers with different signs where the exact mathematical result is zero evaluates to -0.

BigInt Operands

The * operator supports BigInt operands, performing arbitrary-precision integer multiplication. However, JavaScript does not allow implicit coercion between Number and BigInt types during arithmetic operations. Both operands must resolve to the same numeric type.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More