The multiplicative operators are part of the arithmetic operators.

There are three multiplicative operators; these are multiply ("*"), divide ("/") and modulus ("%"). These operators work with two values that don't necessarily have to be numbers, in which case they are converted to numbers behind the scene.

Multiply

The multiply operator is represented by an asterisk symbol ("*") and it is used to multiply two numbers, as shown in the example:

`var mult = 34 * "11";`

When working with special values, rather than numbers, these rules are applied:

• If the operands are numbers and the results are not displayable due the size, then the Infinity or -Infinity,depending on the sign, 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 number but "0", the result is either Infinity or -Infinity, depending on the sign, is returned;
• If Infinity is multiplied by Infinity, the result is Infinity;
• If either operand isn't a number, it is converted to a number and then the regular rules apply.

Divide

The divide operator is represented by a slash symbol ("/") and it is used to divide the first operand by the second one, as shown in the example:

`var divs = 34 / "11";`

When working with special values, rather than numbers, these rules are applied:

• If the operands are numbers and the results are not displayable, then the Infinity or -Infinity,depending on the sign, is returned;
• If either operand is NaN, the result is NaN;
• If Infinity is divided by "0", the result is NaN;
• If a non-zero finite number is divided by "0", the result is either Infinity or -Infinity, depending on the sign;
• If Infinity is divided by any number but "0", the result is Infinity or -Infinity, depending on the sign;
• If either operand isn't a number, it is converted to a number and then the regular rules apply.

Modulus

The modulus operator is represented by a percent symbol ("%") and it is used to present the remaining number after a regular integer based division. The example below shows how it works:

`var modul = 34 % 11; //equals 1 ((11*3)+1=34)`

When working with special values, rather than numbers, these rules are applied:

• If the dividend is an infinite number and the divisor a finite one, the result is NaN;
• If the dividend is a finite number and the divisor is "0", the result is NaN;
• If Infinity is divided by Infinity, the result is NaN;
• If the dividend is a finite number and the divisor is an infinite number, then the result is the dividend;
• If the dividend is "0", the result is "0";
• If either operand isn't a number, it is converted to a number and then the regular rules apply.

Example

The example with multiplicative (arithmetic) operators in JavaScript:

›› go to examples ››