diff --git a/README.md b/README.md index bb50312..5a501e9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_679 TILs and counting..._ +_680 TILs and counting..._ --- @@ -234,6 +234,7 @@ _679 TILs and counting..._ - [Computed Property Names In ES6](javascript/computed-property-names-in-es6.md) - [Configure Jest To Run A Test Setup File](javascript/configure-jest-to-run-a-test-setup-file.md) - [Create An Array Containing 1 To N](javascript/create-an-array-containing-1-to-n.md) +- [Create An Object With No Properties](javascript/create-an-object-with-no-properties.md) - [Create Bootstrapped Apps With Yarn](javascript/create-bootstrapped-apps-with-yarn.md) - [Custom Type Checking Error Messages With Yup](javascript/custom-type-checking-error-messages-with-yup.md) - [Default And Named Exports From The Same Module](javascript/default-and-named-exports-from-the-same-module.md) diff --git a/javascript/create-an-object-with-no-properties.md b/javascript/create-an-object-with-no-properties.md new file mode 100644 index 0000000..04cddab --- /dev/null +++ b/javascript/create-an-object-with-no-properties.md @@ -0,0 +1,26 @@ +# Create An Object With No Properties + +When you call `new Object` or even just instantiate an object with `{}`, you +are creating an object that uses the `Object` prototype. This means it +inherits from `Object.prototype`. + +You can deliberately create an object with no properties by making sure that +it does not inherit `Object.prototype`. + +```javascript +> const propertylessObject = Object.create(null); +{} + +> propertylessObject.__proto__ +undefined +``` + +Unlike most objects that we encounter as we write JavaScript, this object we +created with `Object.create(null)` has no properties including no +`__proto__`. + +See +[Object.create](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) +and +[Object.prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype) +for more details.