The first lesson of Javascriptip study

Source: Internet
Author: User
Tags type null

1. Basic knowledge:

Data type:

1. Type analysis:

There are 8 kinds of data types in JS, the first 5 is the base type and the last 3 are reference types.

The difference between Undefined,null,nan in the focus 1:js:

From the above code and running results, it can be seen that undefined values and definitions are unassigned for Undefined,null is a special Object,nan is a special number.

The operational comparison of Undefined,null,nan in key 2:JS:

From the above code, it can be concluded that(1) undefined is equal to NULL, and (2) Nan is not equal to any value, nor is it equal to itself.

Null data type in JSCRIPT data type null has only one value: null. The keyword NULL cannot be used as the name of a function or variable. A variable containing null contains either "No value" or "no object". In other words, the variable does not hold a valid number, String, Boolean, array, or object. You can clear the contents of a variable by assigning a null value to a variable. Note that in Jscript, NULL is not equal to 0 (unlike in C and C + +). It should also be noted that the typeof operator in JScript will report a null value of type Object, not type null. This potential confusion is for backwards compatibility. The Undefined data type returns a Undefined value if the object property does not exist, but the variable is declared but never assigned a value. Note that you cannot test for the existence of a variable by comparing it with undefined, although you can check whether its type is "undefined". In the following code example, suppose the programmer wants to test whether a variable has been declared X://This method does not work if (x = = undefined)    //Do some operations//This method also does not work-must check//string "und  Efined "if (typeof (x) = = undefined)    //Make certain operations//This method is valid if (typeof (x) = =" undefined ")     Consider comparing the undefined value to null for some operations. Someobject.prop = = NULL; When the following occurs, the result of the comparison is true if the property someobject.prop contains a null value if the property Someobject.prop does not exist. To check whether an object property exists, you can use the new in operator: if ("prop" in Someobject)//someobject has the attribute ' prop ' in JavaScript, null and undefined were once confusing. The following analysis helps you to understand it more clearly (or to make you more confused):-null is the keyword; undefined is a property of the global object-null is an object (empty object, no properties and methods); undefined is a value of type undefined. Try the followingCode:        Document.writeln (typeof null); Return Object        Document.writeln (typeof undefined); Return undefined-object model, all objects are instances of object or its subclasses, but null object exceptions:        Document.writeln ( Null instanceof Object); Return False-null "equivalent (= =)" At Undefined, but not "full equivalent (= = =)" At undefined:        Document.writeln (null = = undefined); return true        document.writeln (null = = = undefined); return false-null and undefined can be cast to false at operation, but not equal to false:        Document.writeln ( !null,!undefined); return true,true        Document.writeln (null==false); return False        Document.writeln (undefined==false); return False
Data type Judging method: typeof ();

As you can see, the reference type is actually only one type of object, A8 = NULL means that A8 is an empty object, not a null type;

The first lesson of Javascriptip study

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.