Skip to content

Instantly share code, notes, and snippets.

@razouck
Last active April 6, 2022 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save razouck/e36b1842362995999de46af47bf49d6c to your computer and use it in GitHub Desktop.
Save razouck/e36b1842362995999de46af47bf49d6c to your computer and use it in GitHub Desktop.
How to Create an Object in JavaScript
var object;
object = {};
object = new Object();
object = new Object(null);
object = new Object(undefined);
object = Object.create(Object.prototype);
object = Reflect.constructor(Object.prototype);
var prop = 'value';
object = { prop };
object = { prop: 'value' };
object = new Object({ prop: 'value' });
object = Reflect.constructor({prop: 'value'});
object = Object.create(Object.prototype, {
prop: {
value: 'value',
writable: true,
enumerable: true,
configurable: true
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment