Create JavaScript Object

By Object() constructor:

var obj = new Object();

By Object.create() method:
Object.create: Will return a new object with properties of prototypeObject.

var obj = Object.create(prototypeObject);

By brackets:
It is the same as Object.create() method with a null parameter.

var obj = {};

By function constructor:

var MySite = function(website) {
  this.website = website;
}
var obj = new MySite("w3schools.com"); 

By function constructor with prototype:

function MySite(){};
MySite.prototype.name = "w3schools.com";
var obj = new MySite();

By ES6 class syntax:

class MySite {
  constructor(name) {
    this.name = name;
  }
}
var obj = new MySite("w3schools.com");

By Singleton pattern:

var obj = new function(){
  this.name = "w3schools.com";
}

Related topics: