How to create objects in JavaScript?



How to create objects in JavaScript?..

Answer / Vandana Srivsatava

In JavaScript, objects can be created in several ways: 1) Object literal syntax (using curly braces): `let obj = {"key": "value"};` 2) Constructing an object using the `new` keyword and a constructor function: `function MyObject() {}; let obj = new MyObject();`. 3) Using the `Object.create()` method to create a new object with specified prototype: `let proto = { prop1: "value" }; let obj = Object.create(proto);`.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

List out the Mouse Events?

1 Answers  


How can javascript be used to improve the "look and feel" of a web site? By the same token, how can javascript be used to improve the user interface?

1 Answers  


What is a null variable?

1 Answers  


Can you run javascript in notepad?

1 Answers  


What are the four types of javascript objects?

1 Answers  


do any browser need activeX object to run javascripts?

2 Answers  


Can I declare a variable as CONSTANT in JavaScript?

1 Answers  


Is javascript insecure?

1 Answers  


What does the term sticky session mean in a web-farm scenario? Why would you use a sticky session? What is the potential disadvantage of using a sticky session?

1 Answers  


How to replace all occurrences of a string in JavaScript?

1 Answers  


How do you implement Ajax using hide() function in JQuery?

2 Answers   QuinStreet,


What are the properties of stack?

1 Answers  


Categories