<?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: Asir Sam R</title>
    <description>The latest articles on DEV Community by Asir Sam R (@asirsamr).</description>
    <link>https://dev.to/asirsamr</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%2F941040%2F89da8e18-4bfd-4bc3-95e5-b1d662f1ce3f.jpg</url>
      <title>DEV Community: Asir Sam R</title>
      <link>https://dev.to/asirsamr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asirsamr"/>
    <language>en</language>
    <item>
      <title>What is Node.js and npm? A Beginner’s Guide</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Mon, 24 Mar 2025 09:46:47 +0000</pubDate>
      <link>https://dev.to/asirsamr/what-is-nodejs-and-npm-a-beginners-guide-cl5</link>
      <guid>https://dev.to/asirsamr/what-is-nodejs-and-npm-a-beginners-guide-cl5</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the world of modern web development, JavaScript has expanded beyond just running in the browser. Thanks to Node.js, developers can now use JavaScript for server-side programming as well. Alongside Node.js, npm (Node Package Manager) plays a crucial role in managing libraries and dependencies. This post will help you understand what Node.js and npm are and why they are essential for JavaScript development.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What is Node.js?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Node.js is an open-source, cross-platform runtime environment that allows you to run JavaScript outside the browser. It is built on Chrome’s V8 JavaScript engine, which compiles JavaScript code into machine code for fast execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Key Features of Node.js:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous and Event-Driven&lt;/strong&gt; – Handles multiple requests simultaneously without blocking the execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-blocking I/O&lt;/strong&gt; – Improves efficiency and performance by processing tasks in parallel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single Programming Language&lt;/strong&gt; – Enables full-stack development using JavaScript for both frontend and backend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt; – Suitable for building real-time applications like chat apps, streaming services, and APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example: Creating a Simple HTTP Server in Node.js&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text/plain&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Server running at http://localhost:3000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This simple server listens on port &lt;code&gt;3000&lt;/code&gt; and responds with “Hello, World!”&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What is npm?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;npm (Node Package Manager) is the default package manager for Node.js. It helps developers install, manage, and share JavaScript libraries and tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why Use npm?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Management&lt;/strong&gt; – Easily install and manage third-party libraries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version Control&lt;/strong&gt; – Maintains project stability by managing package versions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Script Automation&lt;/strong&gt; – Automate tasks using npm scripts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open-source Community&lt;/strong&gt; – Access a vast repository of free-to-use JavaScript packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Basic npm Commands:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Initialize a Project&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a &lt;code&gt;package.json&lt;/code&gt; file, which stores project dependencies and metadata.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install a Package (e.g., Express.js)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   npm &lt;span class="nb"&gt;install &lt;/span&gt;express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adds Express to the project and lists it in &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install Packages Globally&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Installs &lt;code&gt;nodemon&lt;/code&gt; globally, allowing automatic server restarts on file changes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Update Dependencies&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   npm update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Updates all installed packages to their latest compatible versions.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;How Node.js and npm Work Together&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Node.js provides the runtime for executing JavaScript code outside the browser, while npm simplifies dependency management. Together, they enable developers to create scalable, efficient applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example: Building a Simple Express Server&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello from Express!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Server running on http://localhost:3000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example uses npm to install Express.js and Node.js to run the server.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Node.js and npm have transformed JavaScript into a powerful full-stack development tool. Whether you're building APIs, web applications, or real-time services, understanding these tools is essential. Now that you have a solid foundation, start experimenting and building your own Node.js projects!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Further Reading:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/en/docs/" rel="noopener noreferrer"&gt;Node.js Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.npmjs.com/" rel="noopener noreferrer"&gt;npm Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript Object #14</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Tue, 18 Apr 2023 12:00:25 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-13-1ai9</link>
      <guid>https://dev.to/asirsamr/javascript-object-13-1ai9</guid>
      <description>&lt;p&gt;In the Post we are going to some latest ECMA method introduced in Javasciript.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Object.values()&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To access the value of an Object we usually use &lt;strong&gt;for...in&lt;/strong&gt; loop to iterate over it and access the elements inside the Object.But there is problem with for...in as we have already seen this in past post about for...in loop,that iterates over all the inherited properties of an Object.That is not fair and we have sort that it with &lt;strong&gt;Object.hasOwnProprty()&lt;/strong&gt; method.That's a Good way, but what if we can do it in more easy way.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ES2017 has introduced the &lt;strong&gt;Object.values&lt;/strong&gt; to access the values of an own enumerable properties of an Object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;let's see this with an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`const person = {
    firstName: 'John',
    lastName: 'Doe',
    age: 25
};

for (const key in person) {
    if (person.hasOwnProperty(key)) {
        const value = person[key];
        console.log(value);

    }
}
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`John
Doe
25
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's now see this with the &lt;strong&gt;Object.values()&lt;/strong&gt;,&lt;/p&gt;

&lt;p&gt;The Syntax is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`Object.values(obj)`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`const person = {
    firstName: 'John',
    lastName: 'Doe',
    age: 25
};

const profile = Object.values(person);

console.log(profile);
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`[ 'John', 'Doe', 25 ]
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;Object.values()&lt;/strong&gt; accepts an object and returns its own enumerable property’s values as an array.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Object.entries()&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;As like Object.values(),in ES2017 introduced the &lt;strong&gt;Object.entries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object.entries&lt;/strong&gt; are same like Object.values,but it returns the enumerable &lt;em&gt;string-keyed&lt;/em&gt; property into &lt;strong&gt;[key, value]&lt;/strong&gt; pair of Object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`Object.entries()`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`const ssn = Symbol('ssn');
const person = {
    firstName: 'John',
    lastName: 'Doe',
    age: 25,
    [ssn]: '123-345-789'
};

const kv = Object.entries(person);

console.log(kv);
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`[
    ['firstName', 'John'],
    ['lastName', 'Doe'],
    ['age', 25]
]
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The firstName, lastName, and age are own enumerable string-keyed property of the person object, therefore, they are included in the result.
The ssn is not a string-key property of the person object, so it is not included in the result.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That's all for now,hope you learnt something.Please put down comments suggesting me to do better,that will motivates me a lot to do more in Javascript.&lt;/p&gt;

&lt;p&gt;Thanks for you Time in between breaks,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #13</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Tue, 18 Apr 2023 10:02:21 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-13-ad1</link>
      <guid>https://dev.to/asirsamr/javascript-object-13-ad1</guid>
      <description>&lt;p&gt;In this Post we are going to see the &lt;strong&gt;Object.is()&lt;/strong&gt; method in Javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Object.is()&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is method was introduced later in &lt;strong&gt;ECMASCRIPT17&lt;/strong&gt;,this method is used to compare the two values.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;===&lt;/strong&gt; and &lt;strong&gt;Object.is()&lt;/strong&gt; behaves the same way as the Strict equal,but in two ways they differ.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;-0 and +0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NaN&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Negative zero&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;===&lt;/strong&gt; it treats both the negative and non negative numbers as same or else what we could say is, they are equal.&lt;br&gt;
let's see this with an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let amount = +0,
    volume = -0;
console.log(volume === amount);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`true`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here comes the &lt;strong&gt;Object.is()&lt;/strong&gt; he treat him as they are not same,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let amount = +0,
    volume = -0;
console.log(Object.is(amount, volume));`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`false`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Nan&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here comes another one,as when you compare the &lt;strong&gt;Nan&lt;/strong&gt; with the &lt;strong&gt;===&lt;/strong&gt; operator it will return false,as they think they are not same.&lt;strong&gt;Nan&lt;/strong&gt; is the only number that does not equals itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let quantity = NaN;
console.log(quantity === quantity);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`false`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, Object.is() treats NaN as the same value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let quantity = NaN;

console.log(Object.is(quantity, quantity));


Output:

true`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'll attach a table that can help you a lot and save your many time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh6ragsgerjjcx6basm3w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh6ragsgerjjcx6basm3w.png" alt="Image description" width="800" height="973"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for your mean Time,&lt;br&gt;
Sam.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #12</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Tue, 18 Apr 2023 04:05:39 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-11-2fhj</link>
      <guid>https://dev.to/asirsamr/javascript-object-11-2fhj</guid>
      <description>&lt;p&gt;In this Post we are going to see,how to iterate over an enumerable Property in an Javscript Objects.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;for..in&lt;/strong&gt; loops iterate over the &lt;em&gt;enumerable properties&lt;/em&gt; of an Object.Note that a property can be Keyed by a String or Symbol.A property is enumerable when its &lt;strong&gt;enumerable&lt;/strong&gt; attribute is set to &lt;strong&gt;true&lt;/strong&gt;.By default while creating an Object using literal syntax,the &lt;strong&gt;enumerable&lt;/strong&gt; attribute is set true initially.&lt;/p&gt;

&lt;p&gt;Let's see an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`
object.propertyName = value;

or by

let obj = {
    propertyName: value,
    ...
};

`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in both the cases the Object &lt;strong&gt;enumerable&lt;/strong&gt; property is set to true by default.&lt;/p&gt;

&lt;p&gt;Now let's create a for..loop and iterate over an Object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`for(const propertyName in object) {
    // ...
}
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`var person = {
    firstName: 'John',
    lastName: 'Doe',
    ssn: '299-24-2351'
};

for(var prop in person) {
    console.log(prop + ':' + person[prop]);
}
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`firstName:John
lastName:Doe
ssn:299-24-2351
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we used the for...in loop to iterate over the properties of the person object. We accessed the value of each property using the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`object[property];`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The for...in loop &amp;amp; Inheritance
&lt;/h2&gt;

&lt;p&gt;So for we have seen the iteration over a normal Object,but what if we iterate an Object that inherits the property from another Object.The for..in loop will inherit the properties that inherits from the another Object,the &lt;strong&gt;for..in&lt;/strong&gt; goes up in prototype chain and iterate over enumerable properties.Let's see an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`var decoration = {
    color: 'red'
};

var circle = Object.create(decoration);
circle.radius = 10;


for(const prop in circle) {
    console.log(prop);
}
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`radius
color
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The circle object has its own prototype that references the decoration object. Therefore, the for...in loop displays the properties of the circle object and its prototype.&lt;/p&gt;

&lt;p&gt;If you want to enumerate over only the own properties of an Object,you can use &lt;strong&gt;hasOwnProperty()&lt;/strong&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`for(const prop in circle) {
    if(circle.hasOwnProperty(prop)) {
        console.log(prop);
    }
}
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`radius
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The for...in loop and Array
&lt;/h2&gt;

&lt;p&gt;It’s good practice to not use the for...in to iterate over an array, especially when the order of the array elements is important.&lt;/p&gt;

&lt;p&gt;Let's see an example that works flawlessly,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`const items = [10 , 20, 30];
let total = 0;

for(const item in items) {
    total += items[item];
}
console.log(total); `&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However we can add a new property to the &lt;strong&gt;Array&lt;/strong&gt; type in the Javascript,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`Array.prototype.foo = 100;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hence, the for...in will not work correctly. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`// somewhere else
Array.prototype.foo = 100;

const items = [10, 20, 30];
let total = 0;

for (var prop in items) {
  console.log({ prop, value: items[prop] });
  total += items[prop];
}
console.log(total);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`{ prop: '0', value: 10 }
{ prop: '1', value: 20 }
{ prop: '2', value: 30 }
{ prop: 'foo', value: 100 }
160`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look at this,we have got the wrong once as it has inherites a property from it's prototype.&lt;/p&gt;

&lt;p&gt;Let's see another example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`var arr = [];
// set the third element to 3, other elements are `&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="s2"&gt;`
arr[2] = 3; 

for (let i = 0; i &amp;lt; arr.length; i++) {
    console.log(arr[i]);    
}`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`undefined
undefined
3`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the for...in loop ignores the first two elements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`for (const key in arr) {
    console.log(arr[key]);
}
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`3
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes,that's all for now.If you are reading this Please give me suggestions or comments to motivate me do more and better on upcoming posts.&lt;/p&gt;

&lt;p&gt;Many Thanks for Your Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #11</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Sat, 15 Apr 2023 09:35:14 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-11-2c96</link>
      <guid>https://dev.to/asirsamr/javascript-object-11-2c96</guid>
      <description>&lt;p&gt;Welcome back! in the last post we have seen about the Object properties and it one property Data property.Now we are going to see about the accessor property in this Post.&lt;/p&gt;

&lt;p&gt;As like Data Properties,accessor property have [[Configurable]] and [[Enumerable]] attributes.But the accessor property have the [[Get]] and [[Set]] attributes instead of [[Value]] and [[Writable]].&lt;/p&gt;

&lt;p&gt;When you want to read a data from the accessor property the [[Get]] method is automatically called to return a value.when you want to assign a value to the property [[Set]] function is called automatically.&lt;/p&gt;

&lt;p&gt;To define a accessor property,you need to use Object.defineProperty() method. or example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let person = {
    firstName: 'John',
    lastName: 'Doe'
}

Object.defineProperty(person, 'fullName', {
    get: function () {
        return this.firstName + ' ' + this.lastName;
    },
    set: function (value) {
        let parts = value.split(' ');
        if (parts.length == 2) {
            this.firstName = parts[0];
            this.lastName = parts[1];
        } else {
            throw 'Invalid name format';
        }
    }
});

console.log(person.fullName);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`'John Doe'`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in this example,the Person Object conatins two properties,firstName and lastName.Then we are adding the fullName property to the Person Oject as an accessor property.In the fullName accessor property,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The [[Get]] returns the full name that is the result of concatenating of firstName, space, and lastName.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The [[Set]] method splits the argument by the space and assigns the firstName and lastName properties the corresponding parts of the name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the full name is not in the correct format i.e., first name, space, and last name, it will throw an error.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the ES5,we can define a multiple property in a single statement using the Object.defineProperties() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`var product = {};

Object.defineProperties(product, {
    name: {
        value: 'Smartphone'
    },
    price: {
        value: 799
    },
    tax: {
        value: 0.1
    },
    netPrice: {
        get: function () {
            return this.price * (1 + this.tax);
        }
    }
});

console.log('The net price of a ' + product.name + ' is ' + product.netPrice.toFixed(2) + ' USD');`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`The net price of a Smartphone is 878.90 USD`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we defined three data properties: name, price, and tax, and one accessor property netPrice for the product object.&lt;/p&gt;

&lt;p&gt;In Javascript we can also find the property descriptor of an Object using the Object.getOwnPropertyDescriptor() method,The Object.getOwnPropertyDescriptor() method takes two arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An Object.&lt;/li&gt;
&lt;li&gt;A Property of an Object.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It returns a descriptor object that describes a property. The descriptor object has four properties: configurable, enumerable, writable, and value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let person = {
    firstName: 'John',
    lastName: 'Doe'
};


let descriptor = Object.getOwnPropertyDescriptor(person, 'firstName');

console.log(descriptor);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`{ value: 'John',
  writable: true,
  enumerable: true,
  configurable: true }`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all about the Javascript Object Properties.We will see more          intersting things about Object in Upcoming Post.&lt;/p&gt;

&lt;p&gt;If you are reading this post,and find helpfull.Please give a like and comments that will motivate me a lot and do more interesting things in Javascript.&lt;/p&gt;

&lt;p&gt;Thanks for your mean Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #10</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Sat, 15 Apr 2023 06:21:40 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-10-2c9g</link>
      <guid>https://dev.to/asirsamr/javascript-object-10-2c9g</guid>
      <description>&lt;p&gt;So far in our long Javascript Object post,we have seen about Javascript Object creation, what is Object properties, etc. But in the post we are going to see &lt;strong&gt;Object properties&lt;/strong&gt; in Javascript.This may make you little confusing,because as we have already came through Object Properties as it was the collection unordered keys and values. But this is not same,this is really different.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object Properties
&lt;/h2&gt;

&lt;p&gt;Javascript Object properties are some of the internal attributes of the Object that define the Object characteristics.They can be defined mannually.These attributes are internal and ususally they are sorrounded by two Squre brackets.We can assign the characteristic of the individual properties,that does'nt affect the other properties in the Object.&lt;/p&gt;

&lt;p&gt;Objects have two types of Properties,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Data Properties.&lt;/li&gt;
&lt;li&gt;Accessor Properties.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Data Properties
&lt;/h2&gt;

&lt;p&gt;Data Properties contains the single location for the value.that means the data of the property is stored in the a single attribute.&lt;br&gt;
There are four types of attributes in Data property.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;[[Configurarable]]&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;[[Enumerable]]&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;[[Writable]]&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;[[Value]]&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By default all the internal properties attributes are set to true,while creating an Object.The default value of the attribute &lt;strong&gt;[[Value]]&lt;/strong&gt; is &lt;strong&gt;undefined&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;[[Configurarable]]&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is the first attribute of the Object data property,this defines weather the data in the Object can be &lt;strong&gt;redefined&lt;/strong&gt; or either can delete via &lt;strong&gt;Delete&lt;/strong&gt; Operator.&lt;/p&gt;

&lt;p&gt;To define the Charateristic of a property in an Object.we have to use define property method, *&lt;em&gt;Object.defineProperty() *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This *&lt;em&gt;Object.defineProperty() *&lt;/em&gt; accepts the three arguments,&lt;br&gt;
1.The Object to define.&lt;br&gt;
2.The name of the Property in the Object.&lt;br&gt;
3.A property descriptor object that has four properties: configurable, enumerable, writable, and value.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt; If you Define a new Property using the &lt;strong&gt;Object.defineProperty()&lt;/strong&gt; ,all the internal attributes of the property is set the default &lt;em&gt;false&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let's make this in an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ross&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rachael&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example we have create an Object with two properties,Let's now try to delete the firstName property&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`delete person.firstName;
console.log(person.firstName);`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`undefined`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom,the firstName property have been deleted,as you haven't assigned any internal attributes mannually so the  default value of the [[Configurable]] attribute is set to true.so you can remove it via the delete operator.&lt;/p&gt;

&lt;p&gt;Let's now define a property using the &lt;strong&gt;Object.defineProperty&lt;/strong&gt;,and see what is going to happen,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let person = {};

Object.defineProperty(person, 'ssn', {
    configurable: false,
    value: '012-38-9119'
});

Object.defineProperty(person, 'ssn', {
    configurable: true
});
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`TypeError: Cannot redefine property: ssn`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see,it throws an error.because the we configured the internal attributes to false,so we cannot redefine the property once we set the &lt;strong&gt;configurable&lt;/strong&gt; attribute to &lt;strong&gt;false&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;[[Enumerable]]&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;[[Enumerable]] defines,whether the property can be iterable or not.&lt;br&gt;
By default this attribute is also set TRUE,t means that you can iterate over all object properties using the for...in loop like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`
let person = {};
person.age = 25;
person.ssn = '012-38-9119';

for (let property in person) {
    console.log(property);
}
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`
age
ssn
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's manipulate the Ennumerable property and try this again,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`let person = {};
person.age = 25;
person.ssn = '012-38-9119';

Object.defineProperty(person, 'ssn', {
    enumerable: false
});

for (let prop in person) {
    console.log(prop);
}`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUTPUT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`age`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you can see the ssn property didn't came into console as we have set the enumerable attribute of the property to false.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;[[Writable]]&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This attribute specifies wheater the value of the property can be changed or not.By default this attribute is also set the true.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;[[Value]]&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;As i have told in the beginning the data in the Object in the Data properties are stored in a single location and that is the &lt;strong&gt;[[Value]]&lt;/strong&gt; attribute.This contains the actual value of a property.&lt;/p&gt;

&lt;p&gt;That's it.We will see about the Accessor Property in upcoming post.&lt;/p&gt;

&lt;p&gt;If you are reading this Post Please Hit Up the Like,that motivates me a lot to do and learn more aboyt &lt;strong&gt;Javascirpt&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Many Thanks for your Morning Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Javascript Object #9</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Thu, 13 Apr 2023 06:53:10 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-9-2cpp</link>
      <guid>https://dev.to/asirsamr/javascript-object-9-2cpp</guid>
      <description>&lt;p&gt;We have seen so many important things about Javascript Object.But now we are going to see another most important topic,which is &lt;em&gt;this&lt;/em&gt; in Javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  this
&lt;/h2&gt;

&lt;p&gt;As you may came across many programming languages and have a good familiarity about the &lt;strong&gt;this&lt;/strong&gt; keyword.But in Javascript &lt;strong&gt;this&lt;/strong&gt; keyword in totally different.Let's know about the Strange this keyword in Javasciript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`In Javascript **this** is the Object of which Function is property.In more simple words,**this** reference to the Object of that is currently calling the Function.`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let's see this with an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let counter = {
  count: 0,
  next: function () {
    return ++this.count;
  },
};

counter.next();`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you can see,here counter is an Object and next() is a method inside the counter Object,as you can see inside the Object. The this keyword inside the method references the current Object &lt;strong&gt;counter&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But this is not enough,we have to check the &lt;strong&gt;this&lt;/strong&gt; keyword on differenct context like,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Global Context&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function Context&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Global Context.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`console.log(this === window); // true`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Global context,&lt;strong&gt;this&lt;/strong&gt; refers the Global Object,in Browser it is the Window Object and in NodeJs Environment it is Global Object.And this behaviour is same in both &lt;em&gt;Strict&lt;/em&gt; and &lt;em&gt;non strict&lt;/em&gt; mode.&lt;br&gt;
And If you assign a property with &lt;strong&gt;this&lt;/strong&gt; in Global context,Javascript will add the Property to the window Object,as like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`this.color= 'Red';
console.log(window.color); // 'Red'`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Function Context.
&lt;/h2&gt;

&lt;p&gt;In Javascript you can call the Function in Following ways,&lt;/p&gt;

&lt;p&gt;1.Function Invocation.&lt;br&gt;
2.Method Invocation.&lt;br&gt;
3.Constructor Invocation.&lt;br&gt;
4.indirect Invocation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Function invocation.
&lt;/h2&gt;

&lt;p&gt;Inside the Function the &lt;em&gt;this&lt;/em&gt; keyword differs in Strict and Non Strict mode.let's see&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function show() {
   console.log(this === window); // true
}

show();`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you call the show() function, the this references the global object, which is the window on the web browser and global on Node.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Calling the show() function is the same as:
window.show();
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But in the Strict mode,Javascript sets the &lt;strong&gt;this&lt;/strong&gt; inside the Function context as &lt;strong&gt;undefined&lt;/strong&gt;.Let's see that with an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`"use strict";

function show() {
    console.log(this === undefined);
}

show();`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to enable the Strict mode use the directive &lt;strong&gt;"use strict"&lt;/strong&gt; in the beggining of the Javascript file,or else you can use the Strict mode inside the specific function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function show() {
    "use strict";
    console.log(this === undefined); // true

    function display() {
        console.log(this === undefined); // true
    }
    display();
}

show();`

Output:
true
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the strict mode applies for both the function and Nested function as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method invocation
&lt;/h2&gt;

&lt;p&gt;When you call a method of an Object, Javascript set the &lt;strong&gt;this&lt;/strong&gt; to the Object that contains that method.Let's see this with a quick example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let car = {
    brand: 'Honda',
    getBrand: function () {
        return this.brand;
    }
}

console.log(car.getBrand()); // Honda`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the this object in the getBrand() method references the car object.&lt;/p&gt;

&lt;p&gt;Let's Go little tricky here,as getBrand is a Property of a Object and it can be Stored in variable right.Yes, Let's do it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let brand = car.getBrand;
console.log(brand()); // undefined
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ufff, Strange right.for me too this things looks so strange untill i know the exact reason.when you assign the brand variable with the Object getBrand property,this will assign the Property but what happens is, the brand variable is now in global context and it reference the Global Object,thus inoder to fix this we have to bind the brand variable to the exact Object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let brand = car.getBrand.bind(car);
console.log(brand()); // Honda
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To fix this issue, you use the bind() method of the Function.prototype object. The bind() method creates a new function whose the this keyword is set to a specified value.&lt;/p&gt;

&lt;p&gt;Let's see another example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let car = {
    brand: 'Honda',
    getBrand: function () {
        return this.brand;
    }
}

let bike = {
    brand: 'Harley Davidson'
}

let brand = car.getBrand.bind(bike);
console.log(brand());

Output:

Harley Davidson`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the bind() method sets the this to the bike object, therefore, you see the value of the brand property of the bike object on the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Constructor invocation
&lt;/h2&gt;

&lt;p&gt;When you use the new keyword to create an instance of a function object, you use the function as a constructor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function Car(brand) {
    this.brand = brand;
}

Car.prototype.getBrand = function () {
    return this.brand;
}

let car = new Car('Honda');
console.log(car.getBrand());`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expression new Car('Honda') is a constructor invocation of the Car function.JavaScript creates a new object and sets this to the newly created object. This pattern works great with only one potential problem.&lt;br&gt;
Now, you can invoke the Car() as a function or as a constructor. If you omit the new keyword as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`var bmw = Car('BMW');
console.log(bmw.brand);
// =&amp;gt; TypeError: Cannot read property 'brand' of undefined`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the this value in the Car() sets to the global object, the bmw.brand returns undefined.&lt;/p&gt;

&lt;p&gt;ES6 introduced a meta-property named new.target that allows you to detect whether a function is invoked as a simple invocation or as a constructor.&lt;/p&gt;

&lt;p&gt;You can modify the Car() function that uses the new.target metaproperty as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function Car(brand) {
    if (!new.target) {
        throw Error('Must use the new operator to call the function');
    }
    this.brand = brand;
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Indirect Invocation
&lt;/h2&gt;

&lt;p&gt;In JavaScript, functions are first-class citizens. In other words, functions are objects, which are instances of the Function type.&lt;/p&gt;

&lt;p&gt;The Function type has two methods: call() and apply() . These methods allow you to set the this value when calling a function. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function getBrand(prefix) {
    console.log(prefix + this.brand);
}

let honda = {
    brand: 'Honda'
};
let audi = {
    brand: 'Audi'
};

getBrand.call(honda, "It's a ");
getBrand.call(audi, "It's an ");`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code language: PHP (php)&lt;/p&gt;

&lt;p&gt;In this example, we called the getBrand() function indirectly using the call() method of the getBrand function. We passed honda and  audi object as the first argument of the call() method, therefore, we got the corresponding brand in each call.&lt;/p&gt;

&lt;p&gt;The apply() method is similar to the call() method except that its second argument is an array of arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`getBrand.apply(honda, ["It's a "]); // "It's a Honda"
getBrand.apply(audi, ["It's an "]); // "It's a Audi"`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for You Mean Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>web3</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #8</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Wed, 12 Apr 2023 10:21:47 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-8-3k6m</link>
      <guid>https://dev.to/asirsamr/javascript-object-8-3k6m</guid>
      <description>&lt;p&gt;From the past posts we've seen about Prototype and Prototype Chaining in quite detail.Now we are going to see,how to link methods in the prototype chains and how i will be usefull in our cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining methods in the JavaScript prototype object
&lt;/h2&gt;

&lt;p&gt;The Simple way to define a new method in the Prototype Object is,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Person.prototype.greet = function() {
    return "Hi, I'm " + this.name + "!";
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;by defining like this,Javascript Object add the greet() method to the &lt;strong&gt;Person.prototype&lt;/strong&gt; Object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zsfhh3gowph89sd6xfm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zsfhh3gowph89sd6xfm.png" alt="Image description" width="652" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's create a new instance for the Person,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let p1 = new Person('John');`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Internally Javascript creates a new Object &lt;strong&gt;p1&lt;/strong&gt; and links the Object with &lt;strong&gt;Person.prototype&lt;/strong&gt; via prototype Linkage.&lt;/p&gt;

&lt;p&gt;Let's visaualize it,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53bxhowoi7jsywb002tn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53bxhowoi7jsywb002tn.png" alt="Image description" width="647" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As You can see the Link between the p1, Person.prototype and Object.prototype is called as the &lt;strong&gt;Prototye Chain&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now let's access the methods inside the Prototype Object,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let greeting = p1.greet();
console.log(greeting);`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you can see p1 doesn't have the greet() method and the javascript engine will search for it in the Person.prototype Object.&lt;br&gt;
Since JavaScript can find the greet() method on the Person.prototype object, it executes the greet() method and returns the result&lt;/p&gt;

&lt;p&gt;Now let's call the &lt;strong&gt;toString()&lt;/strong&gt; method and let's see what happens,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let s = p1.toString();
console.log(s);`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in this above case, the JavaScript engine follows the prototype chain to look up for the toString() method in the Person.prototype.&lt;br&gt;
in our case the Person.prototype doesn't contains the toString() method and the prototype chain starts to search for it in the Object.prototype Object.Since JavaScript can find the toString() method in the Object.prototype, it executes the toString() method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F49n2xjf8fk3ivekgcq2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F49n2xjf8fk3ivekgcq2t.png" alt="Image description" width="647" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you call the method that does'nt exist in the Person.prototype and Object.prototype.Javscript engine will search through the prototype chain and if it can't find the method it will throw an error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`
p1.study()
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the study() method doesn’t exist on any object in the prototype chain, the JavaScript engine issues the following error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`TypeError: p1.fly is not a function`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's create another instance of Person function with different name,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let p2 = new Person('Jane');`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the p2 object holds all the properties and method p1 holds.&lt;br&gt;
In conclusion, when you define a method on the prototype object, this method is shared by all instances.&lt;/p&gt;

&lt;p&gt;let's create a method in the individual Object instead of in prototype,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`p2.draw = function () {
    return "I can draw.";
};
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The JavaScript engine adds the draw() method to the p2 object, not the Person.prototype object:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dmmlyd13f8mte82akzu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dmmlyd13f8mte82akzu.png" alt="Image description" width="647" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It means that you can call the draw() method on the p2 object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`p2.draw();`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you cannot call the draw() method on the p1 object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`p1.draw()
`
TypeError: p1.draw is not a function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you define a method in an object, the method is only available to that object. It cannot be shared with other objects by default.&lt;/p&gt;

&lt;p&gt;that's all now for Prototypal Linkage in Javascript.I hope you all got good understanding in prototypal linkage.if you feel any diffuculties feel free to ask me in the comments.&lt;/p&gt;

&lt;p&gt;Many Thanks for your valuable Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #7</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Wed, 12 Apr 2023 04:30:45 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-7-9ie</link>
      <guid>https://dev.to/asirsamr/javascript-object-7-9ie</guid>
      <description>&lt;p&gt;Welcome All,in the last post we've seen what is Prototype in Object.In Javascript every Object contains a Prototype property and it itself is an another Object and it contains many useful methods.&lt;br&gt;
Now we are going to see about the Prototypal Linkage in Object,as from the last post we have seen that Javascript doesn't conatains classical inheritance instead it has &lt;strong&gt;Prototypal Inheritance&lt;/strong&gt; in the Post we are Going to see about the How this Proto Inheritance is  happening.&lt;/p&gt;
&lt;h2&gt;
  
  
  PROTOTYPAL INHERITANCE
&lt;/h2&gt;

&lt;p&gt;Most of the People Don't know that Javascript has an inbuild Function called &lt;strong&gt;Object()&lt;/strong&gt; most of the Novice developers think that it is Just an Object,but it is not an Object.while you console log this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`typeof(Object)

output
'function'

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

&lt;/div&gt;



&lt;p&gt;Pretty Confusing right, yeah may be at the beginning it will, as you been new to Javascript Prototype.&lt;/p&gt;

&lt;p&gt;Javascipt also has an &lt;em&gt;anonymous object&lt;/em&gt; and that can be referenced via &lt;strong&gt;Object.prototype&lt;/strong&gt;.as you can see,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`console.log(Object.prototype);`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh69hjswctkfayoozeyfk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh69hjswctkfayoozeyfk.png" alt="Image description" width="769" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the Object.prototype has some usefull properties like &lt;em&gt;toString&lt;/em&gt;,_ valueOf_ and it also has some important property called &lt;em&gt;constructor&lt;/em&gt; and it reference to and  &lt;em&gt;Object()&lt;/em&gt; function.this is how Javascript Object linking together for example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`console.log(Object.prototype.constructor === Object); // true`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you can see both are same,&lt;/p&gt;

&lt;p&gt;Let's visaulize this in more better way,assume circle as a Object() function and Square as an Object.let illustrate the relationship between them,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7fete3gg6dpek3wpnlma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7fete3gg6dpek3wpnlma.png" alt="Image description" width="393" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;thus,this how they linked together.&lt;/p&gt;

&lt;p&gt;Let's first define a Constructor Function,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wjhwm9g3sf3ugj0ib05.png)
`function Person(name) {
    this.name = name;
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this Fuction,it accepts an argument called name and assign it to the name Property of &lt;strong&gt;this&lt;/strong&gt; Object.&lt;/p&gt;

&lt;p&gt;But do you know what's happening behind the scenes,the Javascirpt engine will create an Function Person and an anonymous Object.Like the Object() Function.Person function has a Prototype Property and it reference the anonymous Object and the Object has a constructor Property that holds the Person() function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbco2hkqalmt1jgesrzg6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbco2hkqalmt1jgesrzg6.png" alt="Image description" width="392" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition,Javascript links the Person.prototype and Object.Prototype Object via the &lt;strong&gt;[Prototype]&lt;/strong&gt;,which is know as the &lt;strong&gt;Prototypal Linkage&lt;/strong&gt;.This is called The Prototypal linkage in the Javascript&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foyp63r2fxrsafuwkd2b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foyp63r2fxrsafuwkd2b4.png" alt="Image description" width="652" height="364"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So for,we have seen how Prototypal Linkage is Happening in Javascirpt Object.In future Post we'll see how to methods are linking using the real time examples.&lt;/p&gt;

&lt;p&gt;Please Support me by giving a reaction to this post,&lt;br&gt;
If you've learned something.&lt;/p&gt;

&lt;p&gt;Many Thanks for You Patience and Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #6</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Tue, 11 Apr 2023 04:22:59 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-6-2a71</link>
      <guid>https://dev.to/asirsamr/javascript-object-6-2a71</guid>
      <description>&lt;p&gt;Welcome All,&lt;/p&gt;

&lt;p&gt;Till our Last Post we've seen only pretty basics in Javascript.From now we are going to Jump into little deep about Objects in Javascript,as i've told you that Javascript Object are very Deep and He is very Strong one,as most of the things in javascript is an Object.&lt;/p&gt;

&lt;p&gt;Let's Quick Dive into it,in this Post we are Going to know about &lt;strong&gt;Prototype&lt;/strong&gt; in Javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prototype
&lt;/h2&gt;

&lt;p&gt;As in many Programming Languages,they have &lt;em&gt;Inheritance&lt;/em&gt; to access the Feature from his Parent class or Object.As like that Javascript can inherit features from one Object to another Object via Prototype.Unlike in other Programming languages like Java,C++ they have Classical Inheritance but in Javascript it is &lt;strong&gt;Prototypal Inheritance&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Every Object has it's own Property called Prototype.And Prototype itself is an another Object and it contains another prototype and it is somewhat called as the &lt;em&gt;Prototype Chain&lt;/em&gt;.This Chain ends when it's Prototype is null.&lt;/p&gt;

&lt;p&gt;Suppose you have an object person with a property called name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let person = {'name' : 'John'}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When examining the person object in the console, you’ll find that the person object has a property called prototype denoted by the [[Prototype]]&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh5ikihbzgakmdel6td4x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh5ikihbzgakmdel6td4x.png" alt="Image description" width="429" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The prototype itself is an object with its own properties:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7qow8cn6bckodwx0vur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe7qow8cn6bckodwx0vur.png" alt="Image description" width="561" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose if you want to access a property from an Object it'll return the value if exist,or else if the Property is not present in the Object the Javascript engine will search for the Property in the Object Prototype and even if it can't find it there it'll search it in the Prototype's Prototype untill it finds the Property or reaches the end of the prototype Chain.&lt;/p&gt;

&lt;p&gt;For example, you can call the toString() method of the person object like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvadhx2q2ofdunmi93ufp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvadhx2q2ofdunmi93ufp.png" alt="Image description" width="215" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The toString() method returns the string representation of the person object. By default, it’s [object Object] which is not obvious.&lt;/p&gt;

&lt;p&gt;In this example on calling the toString() method,the Javascript engine will search for it in the Person Object and it could not find it there and it continue to search for it in the Object Prototype and it will find it there.&lt;/p&gt;

&lt;p&gt;Since the person’s prototype has the toString() method, JavaScript calls the toString() of the person’s prototype object&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftowixrc2v7623x0b29th.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftowixrc2v7623x0b29th.png" alt="Image description" width="490" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;for now that's it,we'll see more intresting things about the Prototype and it's inheritance in upcoming post.&lt;/p&gt;

&lt;p&gt;Many Thanks for Your Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #5</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Wed, 05 Apr 2023 11:55:50 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-5-4nke</link>
      <guid>https://dev.to/asirsamr/javascript-object-5-4nke</guid>
      <description>&lt;p&gt;Very Warm Welcome,&lt;br&gt;
As it was very warm here in mid-afternoon of mid-summer days&lt;br&gt;
In the last Chapter we've created an Object using the Constructor function,as i told we have to call the Constructor Function with "&lt;strong&gt;new&lt;/strong&gt;" keyword.But whatif we call that without the new keyword.let's see about that in this Post.&lt;/p&gt;

&lt;p&gt;Technically, you can call a constructor function like a regular function without using the new keyword like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let friends = Name('Joey','Chandler');`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the Person just executes like a regular function. Therefore, the this inside the Person function doesn’t bind to the person variable but the global object.&lt;/p&gt;

&lt;p&gt;If you attempt to access the firstName or lastName property, you’ll get an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`console.log(person.firstName);

TypeError: Cannot read property 'firstName' of undefined
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, you cannot access the getFullName() method since it’s bound to the global object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`person.getFullName();
Code language: CSS (css)

Error:

TypeError: Cannot read property 'getFullName' of undefined`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inoder to Prevent this ES6 has introduced new property called &lt;em&gt;new.target&lt;/em&gt;.&lt;br&gt;
If the constructor called with the new keyword it would return the reference of the Function.Otherwise it'll return &lt;em&gt;undefined&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let's see example for the property,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function Person(firstName, lastName) {
    if (!new.target) {
        throw Error("Cannot be called without the new keyword");
    }

    this.firstName = firstName;
    this.lastName = lastName;
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this Block,if You call the Construction function with new keyword it will return the new Object otherwise it'll throw an error.&lt;/p&gt;

&lt;p&gt;Alternatively we can also do another way to fix this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`
function Person(firstName, lastName) {
    if (!new.target) {
        return new Person(firstName, lastName);
    }

    this.firstName = firstName;
    this.lastName = lastName;
}

let person = Name("Joe", "Phoebhe");

console.log(person.firstName);`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus it'll return new Object even though we call the Constructor Function without new keyword.&lt;/p&gt;

&lt;p&gt;That's for now,we'll meet in future Object Post,Bye..&lt;/p&gt;

&lt;p&gt;Thanks for you warm Time,&lt;br&gt;
Sam&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Javascript Object #4</title>
      <dc:creator>Asir Sam R</dc:creator>
      <pubDate>Wed, 05 Apr 2023 10:31:56 +0000</pubDate>
      <link>https://dev.to/asirsamr/javascript-object-4-26n7</link>
      <guid>https://dev.to/asirsamr/javascript-object-4-26n7</guid>
      <description>&lt;p&gt;In the last Chapter we've seen a piece of closure called "&lt;em&gt;Lexical Enviroment&lt;/em&gt;",Let put that in hold for now and get back into our Object series in this Blog.&lt;/p&gt;

&lt;p&gt;In the Begginning Chapter we learnt what is object and how to create it.In the Past Chapter we've created the object using Object literal syntax.Now we are going to create an Object using the &lt;strong&gt;CONSTRUCTOR&lt;/strong&gt; Syntax.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CONSTRUCTOR OBJECT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before creating the Object,let know about the use cases of Object created using Constructor Syntax,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    firstName: 'Rachael',
    lastName: 'Ross'
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you can see this is the basic method of creating an Object using literal Syntax,What If, we wan't to create same Object multiple times but with Different values,here comes the Constructor syntax into use,&lt;/p&gt;

&lt;p&gt;The basic Syntax is,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function Name(firstName, lastName){
         this.firstName = firstName;
         this.lastName = lastName;
}
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the basic syntax of the Construtor Function,These are as like Normal Function but the rules to call a constructor functions was,&lt;/p&gt;

&lt;p&gt;1.The name of a constructor function starts with a capital letter like Person, Document, etc.&lt;br&gt;
2.A constructor function should be called only with the new operator.&lt;/p&gt;

&lt;p&gt;Now let's create an Object with our Constructor Function,&lt;/p&gt;

&lt;p&gt;In order to create a new Object,we need to call our Function "&lt;strong&gt;New&lt;/strong&gt;" keyword to create a new instance of an Object &lt;/p&gt;

&lt;p&gt;For Example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let friends = new Name('Chandler','Monica');
`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it very quite right,Then what's go behind this while Creating the new Objects.&lt;/p&gt;

&lt;p&gt;1.Create a new empty object and assign it to the this variable.&lt;br&gt;
2.Assign the arguments 'Chandler' and 'Monica' to the firstName and lastName properties of the object.&lt;br&gt;
3.Return the 'this' value.&lt;/p&gt;

&lt;p&gt;So,this might be equivalent to the &lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
function Name(firstName, lastName) {&lt;br&gt;
    // this = {};&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// add properties to this
this.firstName = firstName;
this.lastName = lastName;

// return this;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;br&gt;
`&lt;br&gt;
Pretty Straigt.We can also add method to the Constructor function,&lt;br&gt;
let's create a method to get the fullname of an Object,as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function Name(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;

    this.getFullName = function () {
        return this.firstName + " " + this.lastName;
    };
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we've added a method to our function.Let's call it out &lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;br&gt;
let friends = new Name('Ross','Rachael');&lt;br&gt;
console.log(person.getFullName());&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Ross Rachael&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Simple but not  efficient,because whenever you create a new instance for every Object getFullName() will be duplicated and it is not memory efficient.Inorder to overcome this,we can create this method in the Object "&lt;strong&gt;Prototype&lt;/strong&gt;" so that every instance of that type can use the method.&lt;/p&gt;

&lt;p&gt;what if we use return inside the constructor function,&lt;br&gt;
Returning from constructor functions&lt;/p&gt;

&lt;p&gt;Typically, a constructor function implicitly returns this that set to the newly created object. But if it has a return statement, then here’s are the rules:&lt;/p&gt;

&lt;p&gt;1.If return is called with an object, the constructor function returns that object instead of this.&lt;br&gt;
   2.If return is called with a value other than an object, it is ignored.&lt;/p&gt;

&lt;p&gt;That's all about Constructor Function now,we'll see more about this in upcoming post.&lt;/p&gt;

&lt;p&gt;Many Thanks for Your Time,&lt;br&gt;
Sam &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
