I have been using following code but what does it mean in javascript?


I have been using these lines in my projects but i do not know what does it exactly means, can anyone please tell me what does it mean exactly.



That declares myObject on the global scope. If it was existing before it takes the existing value, or if it is not existing it assigns it to a new empty object (Read on). This is a common technique if multiple scripts assign properties of the same object, so that it doesn't matter which script got executed first they will always end up with the same result.



Thats an IIFE were the context gets myObject, that allows you to write to the object easily with



The IIFE also makes sure that your variables that you declared inside the function, e.g.:



are not part of the global scope, so they are not polluting the global namespace.



Notice that inside the IIFE you can access myObject as you wish. See in the below snippet how the printed object is the one created with a key custom and a value associated value.








By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

The Dalles, Oregon

眉山市

清晰法令