Logo

JavaScript: NaN

Some operations with infinity, for example, dividing infinity by infinity, return a weird result. In math, this operation has no numerical equivalent. In JavaScript, you'll get NaN.

Infinity / Infinity; // NaN

NaN is a special value, "not a number", that usually indicates execution of a meaningless operation. Any operation with NaN returns NaN.

NaN + 1; // NaN

NaN is a peculiar value. Although it means "not a number", it belongs to the number data type. What a paradox. NaN is never a value you want to see, it appears only as a result of errors. If you come across it, find the point where the operation that wasn't valid for numbers was performed, and correct the piece of code.

Instructions

Execute the operation that returns NaN and print it using console.log().

Tips

If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:

  • Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Found a bug? Have something to add? Pull requests are welcome!