Description of the Undefined/null type in JavaScript

Source: Internet
Author: User

1, Overview:

※undefined and Null are two data types in JavaScript (other types are: Boolean, String, Number, Object).

The ※undefined type has only one value: The Undefined;null type has only one value: null.

2,undefined Type Related instructions:

※ The value of this variable is undefined when the Var is used to declare the relevant variable but is not initialized.

※ This is different from the non-declared (that is, undefined) variables, if the use of undeclared variables, will be an error referenceerror:s is not defined.

※ Only one action is allowed for variables that have not been declared: The typeof operator is used to detect its data type, but it is confusing that the typeof operator, which executes uninitialized and undeclared variables, returns the undefined value. This result has its logical rationality, although the two variables from a technical point of view have an essential difference, but in fact, no matter what kind of variable is not possible to perform real operation.

3,null Type Related instructions:

※ First, NULL is an initialized value. From a logical point of view, a null value represents an empty object pointer, so using the TypeOf operator to detect a null value (or a variable that detects a null value) returns a value of "object";

※ As long as the variable intended to save the object does not actually hold the object, it should be explicitly initialized to a null value, which will not only reflect the convention of NULL as a null object pointer, but also help to further differentiate between null and undefined.

4. Other places to be aware of:

※ It says that if an undeclared variable is used, but if it is accessed as a property of an object, even if the property is not declared (defined), it will not error, but return undefined. See the following example:

Alert (SSS);//Error

var o = {}; alert (o.sss);//undefined.

In general, if the property of the Access object returns a undefined value, it means that this property is undefined (and of course, var o = {sss:undefined} also returns undefined).

Description of the Undefined/null type 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.