The divide operator (
var num1 = 10; var num2 = 2; var result = num1 / num2; console.log(result); // Output: 5
In this example, the values of
num2 are divided using the divide operator, and the result is stored in the variable
result. The value of
result is then logged to the console.
The divide operator can be used with operands of any numeric type, including integers, floating-point numbers, and
0 results in
-Infinity, not an error. To check if a division would result in division by 0, you can use an if statement to check the value of the second operand before performing the division.