Difference between null and undefined in Web Javascript

Source: Internet
Author: User
  • Null
  1. Is a javascript keyword
  2. Is an object type, but is often divided into a separate type
  3. No value
  • Undefined
  1. It also indicates that there is no value, but it is a deeper level, or a system level.
  2. It is not a type, it is a pre-defined global variable
  3. The type is undefined.
  • Undefined mainly appears in
  1. The variable has been defined but is initialized.
  2. Defined parameters that are not passed when a function is called
  3. A property that does not exist under an object
  4. Nonexistent array element
  5. Functions without return values
  • Their Similarities and Differences and relationships
  1. All indicate no value
  2. Swap most of the time
  3. Equality null = undefined returns true
  4. But null! = Undefined returns true
  5. In most cases, undefined is used to define system-level unexpected values that do not exist.
  6. Null is used inProgramThe level is normal or the expected value does not exist. For example, we can use null to initialize the variable: var testvar = NULL; that is to say, if you need to indicate that a variable has no value during programming, null is used. undefined is generally returned by the system.

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.