title: What is the difference between using a function to initialise a JavaScript object with and without return statement?
body: <p>I have two functions to initialise objects. init and differentInit.  </p>
  
  <pre><code>function init(){
      return {a:5};
  }
  
  function differentInit(){
      this.a =5;
  }
  
  obj = init();
  newobj = new differentInit()
  </code></pre>
  
  <p>how are the objects obj and newobj different?<br>
  This is what the JavaScript interpreter shows as the contents of the two objects.</p>
  
  <pre><code>&gt;obj
  &lt;·Object {a: 5}
  &gt;newobj
  &lt;·differentInit {a: 5}
  </code></pre>
  
  <p>EDIT: As the answers (which are really good) have pointed out that <code>newobj</code> has an additional prototype as <code>differentInit.prototype</code>. I had thought an object can only be created with an additional prototype using the <code>Object.create()</code> method. I don't know if this a far too generic question, but how many other ways are there to create objects with prototypes? And can the method used in this question be considered a good way to create an object with prototypes? </p>