DEV Community

stalin s
stalin s

Posted on

JavaScript Objects

In this blog , we will be exploring what are JavaScript objects and its declarations.

What are Objects🤔??.

An object is data that contains key-value pairs within curly braces.

example:

const anObject = {
  key1: 'value1',
  key2: 'value2',
  key3: 'value3',
  // ...
}
Enter fullscreen mode Exit fullscreen mode

Point to be noted : key gives references to a value.

Let's take one real life example of macbook:

const macbook = {
  operatingSystem: 'macOS Sierra',
  screenResolution: '2880x1800',
  screenSize: '15.4 inch',
  usbPorts: 2,
  storage: '512gb',
  // ... Other specs
}
Enter fullscreen mode Exit fullscreen mode

Getting the value of a property.

what are properties in javaScript??

Object keys
are called properties.
example : operatingSystem of macbook.

So we use two method to fetch value of a property.

dot notation

const prop = object.property

bracket notation

const prop = object[property]

Happy Learning

Top comments (0)