Daily discussion -- null, undefined, string (JS)

Source: Internet
Author: User
<! 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 occupation 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 > Summary: </ 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 it is in the stack is both memory usage (of course, allCodeCode segments exist, but 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;
};
// Note that although null is an object type, It is very special and stored in the stack. You can understand it as a special form of object.
// In other object-oriented languages, strings are stored in the heap, but in JS, strings are stored in the stack.
</ Script >
</ Body >
</ Html >

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.