Divide
The divide operator is /.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var result = 6 / 2;
document.writeln(result); //3
</script>
</head>
<body>
</body>
</html>
If either of the operands 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 divide operator has the following behaviors:
OPERAND 1 | divided by | RESULT |
---|---|---|
number | number | regular arithmetic division, may have result of Number.NEGATIVE_INFINITY or Number.POSITIVE_INFINITY |
NaN | any value | NaN |
any value | NaN | NaN |
Infinity | Infinity | NaN |
zero | zero | NaN |
nonzero finite number | zero | Infinity or -Infinity depending on the sign of the first operand |
Infinity | nonzero finite number | Infinity or -Infinity depending on the sign of the second operand |
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Operators:
- JavaScript Operators
- Increment/Decrement Operators
- Increment/Decrement Operators for String, Boolean, Floating-point and Object
- Unary Plus and Minus
- Bitwise Not operator
- Bitwise AND
- Bitwise OR
- Bitwise XOR
- Left Shift
- Signed Right Shift
- Unsigned Right Shift
- Logical NOT
- Logical AND
- Logical OR
- Multiply
- Divide
- Modulus
- Add
- Subtract
- Relational Operators
- Equal and Not Equal
- Identically Equal and Not Identically Equal
- Conditional Operator
- Assignment Operators
- Comma Operator