Javascript Arithmetic Operator Divide

Introduction

There are three multiplicative operators in Javascript: multiply, divide, and modulus.

If either of the operands for a multiplication operation 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 is represented by a slash (/):

let result = 66 / 11; 

The divide operator has special behaviors for special values.

  • If the operands are numbers, regular arithmetic division is performed.
  • If the result can't be represented in Javascript, it returns either Infinity or -Infinity.
  • If either operand is NaN, the result is NaN.
  • If Infinity is divided by Infinity, the result is NaN.
  • If zero is divided by zero, the result is NaN.
  • If a nonzero finite number is divided by zero, the result is either Infinity or -Infinity, depending on the sign of the first operand.
  • If Infinity is divided by any number, the result is either Infinity or -Infinity, depending on the sign of the second operand.
  • If either operand isn't a number, it is converted to a number behind the scenes using Number() and then the other rules are applied.


let firstNumber = 15;
let secondNumber = 10;
let answer;//from   w ww  .  j a v a  2s . co m
answer = 15 / 10;
console.log(answer);

console.log(15 / 10);

answer = firstNumber / secondNumber;
console.log(answer);



PreviousNext

Related