Javascript Arithmetic Operator Multiply

Introduction

There are three multiplicative operators in Javascript: multiply, divide, and modulus.

If either of the operands for a multiplication operation isn't a number, it is converted to a number using the Number() casting function.

An empty string is treated as 0, and the Boolean value of true is treated as 1.

The multiply operator is represented by an asterisk (*).

The syntax is:

let result = 34 * 56; 

The multiply operator has the following unique behaviors when dealing with special values:

  • If the operands are numbers, regular arithmetic multiplication is performed.
  • If the result cannot be represented by Javascript, either Infinity or -Infinity is returned.
  • If either operand is NaN, the result is NaN.
  • If Infinity is multiplied by 0, the result is NaN.
  • If Infinity is multiplied by any finite number other than 0, the result is either Infinity or -Infinity, depending on the sign of the second operand.
  • If Infinity is multiplied by Infinity, the result is Infinity.
  • If either operand isn't a number, it is converted to a number behind the scenes using Number() and then the other rules are applied.



PreviousNext

Related