Trainer thoughts on web design techs and tools

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

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

© Webucator, Inc. All rights reserved. | Toll Free: 877-932-8228 | UK: 0808-101-3484 | From outside the USA: 315-849-2724 | Fax: 315-849-2723