Objects in JavaScript

<p>An&nbsp;<code>Object</code>&nbsp;in JavaScript is a data type that stores a collection of properties in key-value pairs. Each key-value pair is used to define characteristics of any arbitrary item.</p> <p>The key of an&nbsp;<code>Object</code>&nbsp;must be a string, whereas the value can be of any data type (including another object, or function &mdash; also known as a method).</p> <h2>Example:</h2> <ul> <li>A pen has several properties such as colour, brand, material, etc.</li> </ul> <pre> let pen = { colour: &quot;black&quot;, brand: &quot;Pilot&quot;, material: &quot;metal&quot; }</pre> <h1>How can we create objects?</h1> <p>There are two ways which we can do this:</p> <ol> <li>Create an object via the constructor</li> </ol> <pre> let user = new Object();</pre> <p>2. Using the object literal syntax</p> <pre> let user = {};</pre> <h1>How can we assign a property in an object?</h1> <p>There are two ways we can assign a property to an object:</p> <ol> <li>Dot syntax</li> </ol> <pre> let user = {}; user.age = 25;</pre> <p>2. Square brackets</p> <pre> let user = {}; user[&quot;age&quot;] = 25;</pre> <h1>How can we extract a property in an object?</h1> <p>There are two ways we can extract a property in an object</p> <p><a href="https://emily-y-leung.medium.com/objects-in-javascript-f24aaff112e7">Click Here</a></p>