The multiplication operator (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.
*) 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 primitiveNumber 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 bytoString(). The resulting primitive is then coerced to a Numeric type. If the object resolves to aBigIntprimitive, it evaluates as aBigInt. - Booleans:
truecoerces to1,falsecoerces to0. - Strings: Parsed as numeric values. Empty strings (
"") coerce to0. Unparseable strings coerce toNaN. - Null/Undefined:
nullcoerces to0.undefinedcoerces toNaN.
IEEE 754 Floating-Point Precision Loss
Because JavaScriptNumber 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 alwaysNaN. - Infinity: Multiplying
Infinityby a non-zero number results inInfinity(or-Infinitydepending on the sign). - Infinity and Zero: Multiplying
Infinity(or-Infinity) by0(or-0) evaluates toNaN. - 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.
Master JavaScript with Deep Grasping Methodology!Learn More





