Search code examples
javascriptencapsulation

Explain this please: var MYLIBRARY = MYLIBRARY || (function(){


I've stumbled upon construct that I'm not sure what it does

var MYLIBRARY = MYLIBRARY || (function(){

https://stackoverflow.com/a/2190927/680815

I don't have much rep. yet so I can't post a comment to ask about so well, sorry for the mess. :)

Does it mean if MYLIBRARY is defined use it and if not assign encapsulated code?

Thanks,


Solution

  • yes, it does pretty much what you think.

    if MYLIBRARY is defined it is used, if not it is assigned the encapsulated code?