Make an empty object in JavaScript

/ Published in: JavaScript
Save to your folder(s)

`Object.create(null)` is a more memory-efficient way to make objects, but it's not supported in all versions of JavaScript, so you can do the "old-fashioned" `{}` if that function isn't available.

Copy this code and paste it in your HTML
  1. Evan.emptyObject = function() {
  2. if (Object.create) return Object.create(null);
  3. return {};
  4. };

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.