title: Why use this keyword in object constructor Function Javascript
body: <pre><code>var x = new y ('hello');
  
  function y (mes){
      this.mes = mes;
  
      //x.mes = mes;
      //Why using object name will not work, with this it will work. 
      //please read the description what i am trying to ask.
  }
  </code></pre>
  
  <p><strong>Explanation of the problem</strong></p>
  
  <p>I am learning Javascript, From MDN, </p>
  
  <p>I am on the topic working with Object. link is 
  <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects</a></p>
  
  <p>I am on the topic <strong>Using Object Constructor Function</strong> </p>
  
  <p>In here they are basically saying if you want to create similar object use this object constructor function. </p>
  
  <p>First I notice they are using keyword <code>this</code> in the function code. I was kinda confuse, than I google it why they are using <code>this</code> keyword instead of simply using variable. </p>
  
  <p>Than it kinda make sense, as what I understood by my google search is this, that <code>this</code> keyword is refer to the object means object which I am initiating with the keyword <code>new</code>, </p>
  
  <p>so I thought I should be able to use object name directly instead of using the <code>this</code>. </p>
  
  <p>I will just initiate the object before the function, and than  I should be able to use the object name, and it did not work.</p>
  
  <p><strong>(I am aware if I do this, it actually defeat the purpose of using Object Constructor Function, but that not the point is, the point is do I understand what this means in this context or why it did not work.)</strong></p>