DEV Community

David Chappell
David Chappell

Posted on

Everyday objects as JavaScript objects

Furniture. Before we dive into objects lets talk about Values. What is a value? The numerical value of something stored in computer memory.

What's an example of a value? Let's pretend Devon is an object. A key (name) in the object Devon is payRate, his hourly rate of $65/hour is the value assigned to the key.

What's an object? A collection of properties. Each property contains a key (name) and a value. In this example payRate is the key and the numerical value stored in computer memory referring to $65/hour is the value.

What's a method? A method is a function as a value within a property in an object. The function itself is an object with special properties and methods that make it behave the way they do. Let's call the method paySalary in reference to Devon as the object

What do JavaScript objects do and what could they look like?

They allow us to store related values in a convenient structure. Objects allow us to relate methods to the values they should operate on.

We can think of an object as a bookshelf where each shelf represents a key value pair. The value itself is something like an object per ECMAScript 2020.

Everything in JavaScript is an object except for primitive value types

JavaScript has user defined objects and built in objects like (functions, arrays, number, strings, boolean, set, map, date, math etc).

Objects are copied by reference. This means that an object doesn't refer to the value of something, instead it refers to the numerical address stored in memory that the object is pointing to ➡️🤓

Let's look at a code snippet of the objects that match the picture examples:
Image description
Image descriptionImage description

Top comments (0)