JS Essentials
Published in

JS Essentials

Objects in JavaScript

Hello all! In this article we are talking about objects in JavaScript. To understand JavaScript, we need to understand what are the objects in JavaScript.

Objects In Real Life

Just like any other programming languages, we can compare objects in real life. Let’s take an example of a car. There are different properties of a car like a car has a colour. It has a model, design, size, weight, engine etc.

So if we look at the properties of above car we can say that:
- The model of the car is Honda City
- The colour is red
- The engine is 1498 cc
- Transmission type is manual
- The seating capacity of the car is 5
- Fuel tank capacity is 40 L

Similarly objects in programming language have some properties and those properties have some value, like the model of the car is Honda City so property name is ‘model’ and value is ‘Honda City’.

Name — Value Pair

A name which maps to a unique value.

It means a name has some value. A pair which consists of name and value. The name may be defined more than once but only can have one value in any given execution context. The value may have another name/value pair.

Note: We will learn about execution context in detail in upcoming posts.

So in any particular execution context i.e. a section of a code that is running, a name can only exist and be defined with one value.

Example, firstName =Anjali, here name is ‘firstName’ and value is ‘Anjali’. This is the name-value pair.

Objects

When we are talking about objects, we can use this name-value pair concept to define them.

A collection of name-value pairs.

This is the simplex definition when talking about the objects.

student = {
fName: 'John'
lName: 'Doe'
age: '15',
address: {
street: 'DP Rd',
flatNo: '401',
floor: 4
}
}

Suppose we have a name as ‘student’ and the value is a collection of other name-value pairs. fname is a name & value is ‘John’. lName is a name, value is ‘Doe’. address is a name & value is a collection of other name-value pairs. This is an object in JS.

So when we are talking about objects, we are talking about collection of name-value pairs. We are not going into much details right now. We will cover everything step by step in upcoming articles.

I hope objects at basic level are cleared now. In the next article we are going to talk about global objects.

Thank you for reading :)

--

--

--

Place to learn JavaScript concepts in simple manner.

Recommended from Medium

Minimum Binary Heap part 2, remove()

Providing Services Differently in Angular Application

Different levels to provide service

How to trigger animations with React Hooks

Axios vs Fetch (Death Battle)

Merge Sort for Linked Lists

Understanding The JSON structure of EA dashboard-1

Power Set Algorithm with Recursion or Bits

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anjali Tanpure

Anjali Tanpure

JS | Angular | React | PWA

More from Medium

JavaScript: Object

Loved and hated JavaScript

JavaScript

JavaScript Refresher