Nan undefined and null in JavaScript

Source: Internet
Author: User
Tags square root

Null means no value, and undefined represents an undeclared variable, or a variable that has been declared but not assigned a value, or an object property that does not exist.

The NaN property is a special value that represents a non-numeric value. This property is used to indicate that a value is not a number. You can set the number object to this value to indicate that it is not a numeric value.

Null:

Indicates that there is no value, but that null itself is an object in the console execution typeof null result is an object

1 var ob={}; 2 console.log (OB)

The result is: Object {}

var ob; typeof Ob;

Or:

var ob=null; typeof Ob;

The result is: Object



Nan

Some arithmetic operations, such as the square root of a negative number, are not numbers. Methods parseint () and parsefloat () return this value when the specified string cannot be resolved. For some functions that return a valid number in general, you can also use this method to illustrate the error condition with Number.NaN

Such as:

MATH.SQRT (-1);

The result is: NAN

var  Num=1; Num. Nan;console.log (num);

The result of the execution is:

Undefined

But execution isNaN (1) results to False (isNaN's execution result is always Boolean)

Undefined

Undefined corresponds to type undefined, Boolean false, string undefined, numeric calculation result must be Nan

1+undefined;

Execution result is: NAN

Nan undefined and null in JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.