DEV Community

Dharshini E
Dharshini E

Posted on

JavaScript - objects

1.what is object is javascript?
In javascript objcet is a collection key-value paris where the keyis a stringand the value can be anything — a number, string, boolean, array, function, or even another object.
syntax:

let obj = {
  key1: value1,
  key2: value2,
  key3: value3
};
Enter fullscreen mode Exit fullscreen mode

example:

const car = {
type:"Fiat", model:"500", color:"white"
};
Enter fullscreen mode Exit fullscreen mode
  • { } -> object properites - informations are called as propertites.

  • objcet is a variable that can hold variable.

  • you should create object using const.

  • you can also create the empty object.
    empty object:

const person = {};

// Add Properties
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";
Enter fullscreen mode Exit fullscreen mode

Top comments (0)