Operator Perkalian ECMAScript
- Previous Page Logical Operators
- Next Page Additive Operators
Operator perkalian ECMAScript mirip dengan cara operasi operator yang sama di bahasa pemrograman seperti Java, C, dan Perl.
Perlu dicatat bahwa operator perkalian juga memiliki beberapa fungsi konversi otomatis.
Operator perkalian
Operator perkalian ditandai dengan tanda bintang (*), digunakan untuk menggabungkan dua angka.
The syntax of multiplication in ECMAScript is the same as in C language:
var iResult = 12 * 34
However, when dealing with special values, there are some special behaviors in multiplication in ECMAScript:
- If the result is too large or too small, then the generated result is Infinity or -Infinity.
- If any operand is NaN, the result is NaN.
- Infinity multiplied by 0, the result is NaN.
- Infinity multiplied by any number other than 0, the result is Infinity or -Infinity.
- Infinity multiplied by Infinity, the result is Infinity.
Note:If the operand is a number, then perform the usual multiplication operation, that is, two positive numbers or two negative numbers are positive, and the two operands have different signs, the result is negative.
Division Operator
The division operator is represented by the forward slash (/), using the second operand to divide the first operand:
var iResult = 88 / 11;
Similar to the multiplication operator, the division operator also has some special behaviors when dealing with special values:
- If the result is too large or too small, then the generated result is Infinity or -Infinity.
- If any operand is NaN, the result is NaN.
- Infinity divided by Infinity, the result is NaN.
- Infinity divided by any number, the result is Infinity.
- 0 divided by any non-infinite number, the result is NaN.
- Infinity divided by any number other than 0, the result is Infinity or -Infinity.
Note:If the operand is a number, then perform the usual division operation, that is, two positive numbers or two negative numbers are positive, and the two operands have different signs, the result is negative.
Modulus Operator
The division (remainder) operator is represented by the percent sign (%), and the usage is as follows:
var iResult = 26%5; // equals 1
Similar to other multiplicative operators, the modulus operator also has special behaviors for special values:
- If the dividend is Infinity or the divisor is 0, the result is NaN.
- Infinity divided by Infinity, the result is NaN.
- If the divisor is an infinite number, the result is the dividend.
- If the dividend is 0, the result is 0.
Note:If the operand is a number, then perform the usual arithmetic division operation, returning the remainder obtained from the division operation.
- Previous Page Logical Operators
- Next Page Additive Operators