|
Answer» There are various WAYS of CREATING an Object in JavaScript. - With the Object():
Example : VAR name = new Object(); - With Object.create():
Example : var name = Object.create(null); - With the bracket syntactig sugar:
Example : var name = {}; - With a function constructor:
Example : var ObjectName = function(Vname) { this. Vname = Vname } var NewVar = new ObjectName("BestInterviewQuestion.com"); - With function constructor + prototype:
Example : function myObj(){}; myObj.prototype.name = "bestinterviewquestion.com"; var Newk = new myObj(); - With ES6 CLASS:
Example : class myObject { constructor(name) { this.name = name; } } var E = new myObject("bestinterviewquestion.com");
|