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>