Null value in JavaScript, two points of special attention

Source: Internet
Author: User

Null is a JavaScript literal that represents a null value, that is, no object is rendered. He is one of the original JavaScript values. A null value is often placed on an object that is expected, but does not refer to the parameter location of any object, that is, the initialization of the object.

Let's look at one of the following examples

Javascript
var obj = null;console.log (typeof obj = = = = "Object"); True

We understand that by naming a null, NULL is expected on an object and may be set in JavaScript specifications. So return a true. In fact, NULL itself is a literal, return null, why also return object? This should be a bug in the specification.

However, it is important to note that NULL is different from undefined. Undefined is a property of a global variable.

When null or undefined is detected, note the difference between equal (= =) and congruent (= = =) Two operators (the former performs type conversion), so we use the congruent operator (= = =) In the set JavaScript authoring specification, as a comparison, Try doing the following code understanding.

Javascript
NULL = = undefined//Falsenull = = undefined//True

So we have to understand these two points. These are likely to make mistakes when the code makes judgments, and it is also a common problem in the job interview.

This article belongs to Wu Shi Wei's blog, the public number: BIANCHENGDEREN,QQ Group: 186659233 of the original article, reproduced please indicate the source and the corresponding link: http://www.wutongwei.com/front/infor_ showone.tweb?id=162, welcome everyone to spread and share.

Null value in JavaScript, two points of special attention

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.