JavaScript undefined,null type and Nan value difference _ basics

Source: Internet
Author: User
Tags numeric value
A Undefined type
Only one value undefined
In the following three cases typeof return type is undefined
1. When the variable is not initialized
2. When the variable is undefined
3. When the function does not have an explicit return value (the function does not return a value is undefined)
Undefined is not equal to undefined value
typeof does not really distinguish whether it is undefined
Look at the following sample code:
var otemp;
Alert (typeof otemp); Outputs "undefined"
Alert (typeof OTEMP2);//outputs "undefined"
Alert (OTEMP2 = = undefined); Error OTEMP2 undefined cannot use an operation other than typeof that cannot be used OTEMP2
When the variable
Two-Null type
Only one null,undefined is handled by a null derivation, so undefined = = NULL
Undefined is the variable declared but not initialized.
Null indicates an object that does not exist
Three NaN values
is a special value that represents the non-number (not a numbers)
Type conversion fails to return Nan
e.g. to convert a word blue to a numeric value will fail because there is no equivalent value
NaN does not equal himself
That is, Nan = = Nan is False
Judge Nan using isNaN ();
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.