DEV Community

Cover image for Enough JavaScript to get you Started : #10 Objects
Adarsh Pandya
Adarsh Pandya

Posted on

Enough JavaScript to get you Started : #10 Objects

Everything is Object in JS

What are Objects ?

πŸ‘‰ Let's forgot about JS objects and talk about real world objects , every object in real world have certain properties and behaviors.

πŸ‘‰For Example : Girlfriend 😁 , yes ! girlfriend is object , girlfriend have properties like hairColor,eyeColor,name,number,address,likes,dislikes etc...

πŸ‘‰ In JavaScript Object can be defined as group of related properties.

πŸ‘‰ Grouping all the related properties to one thing (ex. Car, GF) makes much more sense , because now it's all stored in one place and is easy to access.

πŸ‘‰ Objects come under category of composite data type , which means mix and match of primitive data types.

How Objects work?

Artboard – 8.png

πŸ‘‰ as we can see we grouped all the related properties under one variable namely girlfriend

πŸ‘‰An object is a collection of properties, and a property is an association between a name (or key) and a value.

Before making object keep in mind

πŸ‘‰ Objects always work in key value pair [eg. name:"john"]

πŸ‘‰ Arrays are always objects in JS.

πŸ‘‰ Functions are always objects in JS.

πŸ‘‰ Objects are always embedded in curly braces {}


var object = {
      property : value,
      property2: value,
Enter fullscreen mode Exit fullscreen mode

The Girlfriend Object 😍

let girlFriend = {
     name : "alexa",
     surname : "grace",
     likes: ["reading","football"],
     number : 123456789
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ We can access object properties using "."

πŸ‘‰ For Example gives output "alexa"

πŸ‘‰ girlFriend.likes gives us array ["reading","football"] as output

Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :)

Keep Coding ❀

Hey , Let' ConnectπŸ‘‹

Twitter / Github

Top comments (0)