javascript wrapper object understanding

First look at a piece of code:

var test = "test";
    test.a = "hello";
console.log(test.a);

 

Result: console.log: undefined

 

understand:

     test.a = "hello";

     A wrapper object is implicitly created here, so the assignment here will not report an error.

     console.log(test.a);

     The previous wrapper object here has been discarded, but the "." operator is used, so a new wrapper object is created, but the property a of this object is not assigned a value, so the value of the property a is undefined.

 

 

Reference: http://www.qdfuns.com/notes/23931/908d7f91530ac100b3a04a8e1ebabb3c.html

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326439812&siteId=291194637