Mar
03
In JavaScript, division by zero does not cause an error. Instead, it evaluates to Infinity, which is a reserved word (note the capital “I”). To see this, run the following code:
alert(5/0);
You’ll get an alert that reads “Infinity”, which is a number:
alert(typeof Infinity); //number alert(isNaN(Infinity)); //false
You can check for an infinite number using the isFinite() function:
isFinite(5/0); //false
There is also negative infinity:
alert(-5/0); //-Infinity
Finally, numbers that are too big or too small for JavaScript to handle evaluate to Infinity:
alert(Math.pow(10,309)); //Infinity
No TweetBacks yet. (Be the first to Tweet this post)





Leave a Reply