Develop advanced tutorials Using Dojo's AJAX applications, part 1th

Source: Internet
Author: User

With the popularity of Ajax applications, the JavaScript language gets more and more attention. Developers are also increasingly using JavaScript. JavaScript is no longer just used to add some fancy effects to the page, it has become an important cornerstone in building Ajax applications. JavaScript, as a dynamic language specifically designed to execute in a browser, has many important features and differs from traditional Java or C + + languages. Familiarity with these features can help developers better develop Ajax applications. This article describes 13 of the more important features in the JavaScript language, including prototype, execution context, scope chain, and closures.

null and undefined

There are 5 basic types in JavaScript, namely String, number, Boolean, Null, and Undefined. The first 3 are better understood, and the back two kinds are slightly more complex. A null type has only one value, or null, and the Undefined type has only one value, that is, Undefined. Both null and undefined can be used directly in JavaScript code as literal (literal).

Null is associated with an object reference, expressed as an empty or nonexistent object reference. When a variable is declared without assigning a value to it, its value is undefined.

The value of the undefined will appear in the following situations:

Gets a property from an object that has a value of undefined if none of the objects in the object and its prototype chain have that property.

A function that returns a value to its caller without an explicit return value is undefined. One special case is when you are using new.

A function in JavaScript can declare any form parameter, and when the function is actually called, the number of arguments passed in is less than the form parameter of the declaration, and the value of the extra formal parameter is undefined.

There are some interesting features about null and undefined:

If you use the typeof operator for a variable with a null value, the result is object, and the undefined value is typeof, and the result is undefined. such as typeof null = = "Object"; typeof undefined = = "undefined"

Null = = undefined, but null!== undefined

if ("" | | 0)

For an if expression, everyone is not unfamiliar. The true and false values of the expressions immediately following the IF in JavaScript are judged to be different from other languages. Please see table 1 for details.

Table 1. True and false values in JavaScript

Type True or False value
Null Always False (false)
Undefined Always False (false)
Boolean Keep the true and false values unchanged
Number +0,-0 or NaN is false, other values are true
String Empty string is false, other value is true
Object Always True (true)

As you can see in table 1, the values in JavaScript that make if judgment false may have null, undefined, false, +0,-0, NaN, and Empty strings ("").

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.