Ankaj Gupta
August 20, 2020

Javascript division by 0

# Javascript Divide by Zero Check

In JavaScript, division by zero does not cause an any error. While, it generates Infinity, which is a reserved word in JavaScript.

Let's try to create simple example:
  • If the division number is positive then it generates positive Infinity.

Example 1 : divided by zero;

  • In this code, we will divide the positive integers by 0.

  1. <script type="text/javascript">
  2. var a = 10, b= 0;

  3. var division;

  4.  

  5. division = a / b;

  6. console.log(division);

  7. </script>
Output :
  • Infinity

  • If the division number is negative then it generates negative -Infinity.

Example 2: divided by zero;

  • In this code, we will divide the negative integers by 0.

  1. <script type="text/javascript">
  2. var a = -10, b= 0;

  3. var division;

  4.  

  5. division = a / b;

  6. console.log(division);

  7. </script>
Output :
  • -Infinity

Recommended Posts:
Code JavaScript Code

Related Posts