Js null, undefined, string Summary

Source: Internet
Author: User

Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> null, undefined, memory usage of strings </title>
<Style type = "text/css">
Body {font-size: 12px ;}
Pre {padding: 5px; border: solid 2px # dfdfdf; color: # fff; background-color: #666 ;}
</Style>
</Head>
<Body>
<Pre>
<Strong> conclusion: </strong>
// Another note is that although null is an Object type, It is very special and stored in the stack itself. You can understand it as a special form of Object.
// In other object-oriented languages, strings are stored in the heap, but in js, the strings are stored in the stack.
// After that, I suddenly thought of the difference between a question and a definition. I thought of it as a thing. Now, when I suddenly want to declare a variable,
// Whether the code is in the stack or not is occupied by memory (of course, all codes will have code segments, but the memory is used, but I am not talking about this ), I mean whether undefined variables exist in the stack.
// After thinking for a while, I think it exists because the undefined type has only one undefined value. When the declared variable is not initialized, the default value is the undefined literal.
// Let's Talk About null. In fact, it should have existed in the heap, but the ECMAscript implementation in the js heap is wrong. Now it is also accepted as a placeholder for an Object.
</Pre>
<Script language = "javascript" type = "text/javascript">
Alert (NaN = NaN); // false
Alert (undefined === undefined); // true
Alert (undefined = null); // true, because undefined is derived from null.
Alert (typeof null );
Alert (undefined === null); // false
// Using the example above, you can write a function to determine whether it is undefined:
Var isUndefined = function (param ){
Return param = undefined;
};
// Another note is that although null is an Object type, It is very special and stored in the stack itself. You can understand it as a special form of Object.
// In other object-oriented languages, strings are stored in the heap, but in js, the strings are stored in the stack.
</Script>
</Body>
</Html>

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.