How to use Multiply Operator in Javascript

Description

The multiply operator is represented by an asterisk *.


var result = 3 * 5;
console.log(result);

If either of the operands isn't a number, it is converted to a number behind the scenes using the Number() casting function. This means that an empty string is treated as 0, and the Boolean value of true is treated as 1.

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 is out of range, either Infinity or -Infinity is returned.
  • If either operand is NaN, the result is NaN.
  • For Infinity * 0, the result is NaN.
  • For Infinity * (any finite number other than 0), the result is either Infinity or -Infinity, depending on the sign of the second operand.
  • For Infinity * Infinity, the result is Infinity.
  • If either operand isn't a number, it is converted to a number using Number().




















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions