<! 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 >