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!

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs