<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Samridhi Vashisht </title>
    <description>The latest articles on DEV Community by Samridhi Vashisht  (@samridhi0545).</description>
    <link>https://dev.to/samridhi0545</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F974823%2F6a1d457c-2112-44e1-bb5e-f22d3c34a43d.jpg</url>
      <title>DEV Community: Samridhi Vashisht </title>
      <link>https://dev.to/samridhi0545</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samridhi0545"/>
    <language>en</language>
    <item>
      <title>Different ways to create objects in JavaScript</title>
      <dc:creator>Samridhi Vashisht </dc:creator>
      <pubDate>Wed, 28 Dec 2022 14:53:52 +0000</pubDate>
      <link>https://dev.to/samridhi0545/different-ways-to-create-objects-in-javascript-2jpm</link>
      <guid>https://dev.to/samridhi0545/different-ways-to-create-objects-in-javascript-2jpm</guid>
      <description>&lt;p&gt;JavaScript is a flexible object-oriented language when it comes to syntax. We will see the different ways to instantiate objects in JavaScript.&lt;/p&gt;

&lt;p&gt;JavaScript is an object-based language that uses prototypes rather than classes. Before we move forward, let's clarify this. JavaScript allows you to create hierarchies of objects and inherit properties and their values based on this different basis.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Creating object with a constructor:&lt;/strong&gt;
Constructor is nothing but a function and with the help of a new keyword, the constructor function allows the creation of multiple objects of the same flavor.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(name) {
  this.name = name;
  this.age = 21;
}
var object = new Person("Sudheer");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using object literals:&lt;/strong&gt; Literals are smaller and simpler ways to define objects. We simply define the property and values inside curly braces.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var object = {
     name: "Samiksha",
     age: 22
};

Object literal property values can be of any data type, including array, function, and nested object.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Creating object with Object.create() method:&lt;/strong&gt; 
This method creates a new object by passing the prototype object as a parameter.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var object = Object.create(null);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using Es6 classes:&lt;/strong&gt;
The class feature to create the objects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person {
  constructor(name) {
    this.name = name;
  }
}

var object = new Person("Samiksha");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Singleton Pattern:&lt;/strong&gt; 
Singletons are objects that only exist once. The constructor returns the same instance every time, so one can avoid accidentally creating multiple instances by repeating the call.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var object = new (function () {
  this.name = "Samiksha";
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>github</category>
    </item>
  </channel>
</rss>
