title: Which way is best for creating an object in JavaScript? Is `var` necessary before an object property?
body: <p>So far I saw three ways for creating an object in JavaScript. Which way is best for creating an object and why?</p>
  
  <p>I also saw that in all of these examples the keyword <code>var</code> is not used before a property — why? Is it not necessary to declare <code>var</code> before the name of a property as it mentioned that properties are variables?</p>
  
  <p>In the second and third way, the name of the object is in upper-case whereas in the first way the name of the object is in lower-case. What case should we use for an object name?</p>
  
  <h3>First way:</h3>
  
  <pre><code>function person(fname, lname, age, eyecolor){
    this.firstname = fname;
    this.lastname = lname;
    this.age = age;
    this.eyecolor = eyecolor;
  }
  
  myFather = new person("John", "Doe", 50, "blue");
  document.write(myFather.firstname + " is " + myFather.age + " years old.");
  </code></pre>
  
  <h3>Second way:</h3>
  
  <pre><code>var Robot = {
    metal: "Titanium",
    killAllHumans: function(){
      alert("Exterminate!");
    }
  };
  
  Robot.killAllHumans();
  </code></pre>
  
  <h3>Third way — JavaScript objects using array syntax:</h3>
  
  <pre><code>var NewObject = {};
  
  NewObject['property1'] = value;
  NewObject['property2'] = value;
  NewObject['method'] = function(){ /* function code here */ }
  </code></pre>