let a = {},b = '0',c = 0; A [b] = '* *' a [c] = 'bill' console, log (a [b]) / / billCopy the code
Object, numeric property names are the same as string property names, and arrays are special strings
Extension: The difference between objects and arrays
let a={}, b=Symbol('1'), c=Symbol('1'); [b] = '* *'; A [c] = 'bill'; console.log(a[b]); / / zhang SANCopy the code
Symbol creates unique values that are not equal. The property name of the object does not have to be a string. If it is a number and a string, it is the same value because the index is a string. Object property names can be null, Symbol, undefined, and so on. Reference type values are stored retrograde as strings.
Extension: Implement a Symbol yourself
let a={}, b={n:'1'}, c={m:'2'}; [b] = '* *'; A [c] = 'bill'; console.log(a[b]); / / li siCopy the code
B, c will be converted to a string when used as a reference, and the Object will be converted to a toString, so that is Object Object
Development: the Object. The prototype. The toString project application, with the valueOf with toString distinction (compile order)
The base type is stored directly, the reference type is put in the heap, and finally the address is copied to the value.
As soon as the page is loaded, it forms a stack memory. Each function execution is called squeezing an execution context onto the stack.
Null, and undefined
// Execute the function immediately. But I is not destroyed because I is occupied. Var test = (function(I){return function(){alert(I *=2); var test = (function(I){alert(I *=2); // If there is no I, look in its parent scope. Where the parent scope is created is who}})(2); test(5); // String 4. There are no parameters in test.Copy the code
The output of alert is converted to a string.
var a=0, b=0; function A(a){ A=function(b){ alert(a+b++); }; alert(a++); } A(1); //"1" A(2); / / "4"Copy the code
Note: a++ is calculated with others, and then accumulates 1; Plus plus a adds 1 to itself, and then you add it to somebody else.
Process explanation:
1, GO global: initialize a = 0, b = 0, a a method, reference address, here temporarily marked as AAAFFF000
A(1) = function (1); Alert (A ++); alert (A ++); alert (A ++); alert (A ++); alert (A ++) So what’s alert is 1 before it’s added
3. Continue to execute A(2), then the function referred to by A is BBBFFF000 after the change, and the parameter b passed in at this time is 2, and A is in its upper scope. It can be seen from Step 2 that it is 2 after superposition, so the alert output should be 2+2. String 4 (alert is automatically converted to toString)
let a = 1;
console.log(5+a++); //6
console.log(a) //2
let b = 1;
console.log(5+(++a)); //7
console.loog(a) //2
Copy the code