NaN

Stands for "Not a Number." NaN is a term used in mathematics and computer science to describe a non-numeric value. It may also be a placeholder for an expected numeric result that cannot be defined as a floating point number.

There are two primary types of ways in which NaN may be generated: 1) a mathematical calculation and 2) non-numeric input. The following mathematical calculations produce NaN because the result is undefined:

  • 0 ÷ 0
  • 0 x ∞
  • ∞ ÷ ∞

When a calculation involves a character, string, or other non-numeric value, the result may also be NaN. For example, 20 x "horse" does not produce a numeric result since 20 is an integer and "horse" is a string. A function may return NaN as a result of invalid input, which is a preferred alternative to a program crash.

Some spreadsheet and database programs display NaN or #NaN in a table cell when the cell formula has not received valid numeric input for the calculation.

Different programming languages handle NaN values in different ways. For example, in JavaScript, NaN is a property of a global object (i.e. Number.NaN). JavaScript provides an isNan() function to check if a value is NaN. PHP uses the function is_nan() for the same purpose. Both return a boolean value of true or false.

Updated June 28, 2018

Definitions by TechTerms.com

The definition of NaN on this page is an original TechTerms.com definition. If you would like to reference this page or cite this definition, you can use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about the NaN definition or would like to suggest a new technical term, please contact us.

Want to learn more tech terms? Subscribe to the daily or weekly newsletter and get featured terms and quizzes delivered to your inbox.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.