DEV Community

Vishal Yadav
Vishal Yadav

Posted on

Creating The object in the JavaScript

  • ## First Method

First of all we create a object of const type then I assign a value to that object and name of that object is object1.
Using the dot operator we access the all element of object1.

const object1={a:'Ajeet Rai',b:'Rajat Yadav',c:'Veeresh Maurya'}; console.log(object1.a); //Ajeet Rai console.log(object1.b); //Rajat Yadav console.log(object1.c); //Veeresh Maurya 
Enter fullscreen mode Exit fullscreen mode
  • ## Second Method

In second method we assign a value to all variable separately and the create a object and assign them.

const a='Uttam'; const b='Sudeep'; const c='Shruti'; const object2={a:a,b:b,c:c}; console.log(object2.a); //Uttam console.log(object2.b); //Sudeep console.log(object2.c); // Shruti 
Enter fullscreen mode Exit fullscreen mode
  • ## Third Method

In this method only different in the assigning the value of the variable in the object3. see in the below example.

const object3={a,b,c}; console.log(object3.a); //Uttam console.log(object3.b); //Sudeep console.log(object3.c); //Shruti 
Enter fullscreen mode Exit fullscreen mode

Hello World!

Top comments (0)