Blog>
Snippets

Creating an Object with No Prototype

Shows how to create an object with no prototype in JavaScript using Object.create(null) and compares it to a regular object literal.
let objWithNoProto = Object.create(null);
console.log(Object.getPrototypeOf(objWithNoProto) === null); // true
Creates an object with no prototype chain, confirming with a console.log that its prototype is 'null'.
let regularObj = {};
console.log(Object.getPrototypeOf(regularObj) === Object.prototype); // true
Creates a regular object literal and confirms that its prototype is Object.prototype.