null,undefined, the memory usage of strings
<br><strong>Summary: </strong> <br>//Another thing to note is that although null It is an Object type but it is very special and is stored in the stack. You can understand it as a special form of Object. <br>//Also, in other object-oriented languages, strings are generally stored in the heap, but in js, they are stored in the stack <br>//After this, a question suddenly occurred to me The difference between declaration and definition, after thinking about it, I feel that it is the same thing, just two ways of saying it. At this time, I suddenly thought that when declaring a variable, <br>//Whether it is on the stack or not, whether it occupies memory (of course all code will exist in code segments, but it uses memory, but that's not what I'm talking about), I mean whether the undefined variable exists on the stack<br>//After thinking about it for a while, I think it does. The reason is that the undefined type has only one value, undefined. When the declared variable is not initialized, of course the default value is the literal value of undefined. . <br>//Let’s talk about null. In fact, it should be stored in the heap, but the js heap ECMAscript was implemented wrong, and now it is accepted by the standard as a placeholder for Object <br>
< ;script language="javascript" type="text/javascript">
alert(NaN == NaN);//false
alert(undefined === undefined);//true
alert( undefined == null);//true, the reason is that undefined is derived from null.
alert(typeof null);
alert(undefined === null); //false
//Through the above example, you can write a function to determine whether it is undefined as follows
var isUndefined = function (param) {
return param === undefined;
};
//Another thing to note is that although null is of type Object, it is very special and is stored in the stack. You can understand it as a special form of Object.
//Also, in other object-oriented languages, strings are generally stored in the heap, but in js, this is stored in the stack
< ;/body>