Question: ```
 var singleton = (function(){

  var instance;

  function init(){

  var privateVariable = 'Private'
  var privateMethod   = function(){ console.log('Am private');}

    return {

    publicField  : 'Public',
    publicMethod : function(){ console.log('Am public');},
    randomVar    : Math.random()
  };
};

return function(){
  if(!instance) { instance = init(); } 
  else { return instance; }
}

})();

var single1 = singleton();
var single2 = singleton();

console.log(single1.randomVar == single2.randomVar);

```

Should return true ,returned: TypeError: single1 is undefined,
But if i removed the IIFE wrap around the function, it works perfectly so i didn't get why is that?

Answer: 
On the initial call you are not returning anything, you are just initializing it - hence the `undefined`. Putting a `return instance` after the initialization call should do the trick.
You either want to add a `return` keyword

```
return function(){
  if(!instance) { return instance = init(); } 
  else { return instance; }
}

```

or omit the `else`:

```
return function(){
  if(!instance) { instance = init(); } 
  return instance;
}

```