<?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: Manikandan K</title>
    <description>The latest articles on DEV Community by Manikandan K (@nameismani).</description>
    <link>https://dev.to/nameismani</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%2F709712%2Fc3e2104b-e7ee-43af-ac72-37d0f01c5d23.jpeg</url>
      <title>DEV Community: Manikandan K</title>
      <link>https://dev.to/nameismani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nameismani"/>
    <language>en</language>
    <item>
      <title>Polymorphism in JavaScript</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Fri, 22 Mar 2024 11:42:17 +0000</pubDate>
      <link>https://dev.to/nameismani/polymorphism-in-javascript-17p3</link>
      <guid>https://dev.to/nameismani/polymorphism-in-javascript-17p3</guid>
      <description>&lt;h2&gt;
  
  
  Explanation:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Polymorphism&lt;/strong&gt;: Polymorphism is a fundamental concept in object-oriented programming where objects of different types can be treated as instances of a common superclass or interface. In this example, polymorphism is demonstrated by the &lt;code&gt;sound()&lt;/code&gt; method, which behaves differently for different types of animals (&lt;code&gt;Animal&lt;/code&gt;, &lt;code&gt;Lion&lt;/code&gt;, &lt;code&gt;Dog&lt;/code&gt;) despite being called using the same interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let Breakdown the term
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The term "polymorphism" indeed breaks down to "poly," meaning "many," and "morph," meaning "form." &lt;/li&gt;
&lt;li&gt;In the context of programming, polymorphism refers to the ability of objects to take on different forms or behave differently based on their specific types or classes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Definition of the Animal class&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Constructor method for initializing an animal with a name&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_animalName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_animalName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Method to make a sound, default implementation for all animals&lt;/span&gt;
    &lt;span class="nf"&gt;sound&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; Definitely makes a sound`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Definition of the Lion class, inheriting from Animal&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Lion&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Constructor method for initializing a Lion with a name&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Calls the constructor of the parent class&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Method to make a sound, specific to Lions&lt;/span&gt;
    &lt;span class="nf"&gt;sound&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; sounds like roaring...`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Definition of the Dog class, inheriting from Animal&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Constructor method for initializing a Dog with a name&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Calls the constructor of the parent class&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Method to make a sound, specific to Dogs&lt;/span&gt;
    &lt;span class="nf"&gt;sound&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; sounds like barking...`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Creating an instance of Animal&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tiger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Stark&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;tiger&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: Animal { name: 'Stark' }&lt;/span&gt;
&lt;span class="nx"&gt;tiger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Stark Definitely makes a sound&lt;/span&gt;

&lt;span class="c1"&gt;// Creating an instance of Lion&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;leo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Lion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Leo&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;leo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: Lion { name: 'Leo' }&lt;/span&gt;
&lt;span class="nx"&gt;leo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Leo sounds like roaring...&lt;/span&gt;

&lt;span class="c1"&gt;// Creating an instance of Dog&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tommy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tommy&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;tommy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: Dog { name: 'Tommy' }&lt;/span&gt;
&lt;span class="nx"&gt;tommy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Tommy sounds like barking...&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Class Definitions&lt;/strong&gt;: Three classes are defined: &lt;code&gt;Animal&lt;/code&gt;, &lt;code&gt;Lion&lt;/code&gt;, and &lt;code&gt;Dog&lt;/code&gt;. Each class represents a type of animal, with &lt;code&gt;Lion&lt;/code&gt; and &lt;code&gt;Dog&lt;/code&gt; inheriting from &lt;code&gt;Animal&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Constructor Methods&lt;/strong&gt;: &lt;br&gt;
Each class has a constructor method that initializes the object with a name. The &lt;code&gt;super()&lt;/code&gt; method is used in the constructor of the derived classes (&lt;code&gt;Lion&lt;/code&gt; and &lt;code&gt;Dog&lt;/code&gt;) to call the constructor of the base class (&lt;code&gt;Animal&lt;/code&gt;) and set the name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;sound()&lt;/code&gt; Method&lt;/strong&gt;: &lt;br&gt;
The &lt;code&gt;sound()&lt;/code&gt; method is defined in the &lt;code&gt;Animal&lt;/code&gt; class as the default behavior for making a sound. However, this method is overridden in the &lt;code&gt;Lion&lt;/code&gt; and &lt;code&gt;Dog&lt;/code&gt; classes to provide specific sound implementations for Lions and Dogs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Instance Creation and Method Invocation&lt;/strong&gt;: &lt;br&gt;
Instances of &lt;code&gt;Animal&lt;/code&gt;, &lt;code&gt;Lion&lt;/code&gt;, and &lt;code&gt;Dog&lt;/code&gt; are created (&lt;code&gt;tiger&lt;/code&gt;, &lt;code&gt;leo&lt;/code&gt;, &lt;code&gt;tommy&lt;/code&gt;), and the &lt;code&gt;sound()&lt;/code&gt; method is called on each instance. Despite being called using the same method name, the actual behavior varies depending on the type of animal due to polymorphism.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Inheritance in JavaScript</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Fri, 22 Mar 2024 10:30:43 +0000</pubDate>
      <link>https://dev.to/nameismani/inheritance-in-javascript-1n7h</link>
      <guid>https://dev.to/nameismani/inheritance-in-javascript-1n7h</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Properties and methods from the base class or parent class can be passed into the derived or child class.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inheritance is a powerful concept in object-oriented programming that allows classes to inherit properties and methods from other classes. &lt;/li&gt;
&lt;li&gt;In JavaScript, class inheritance can be achieved using the &lt;code&gt;extends&lt;/code&gt; keyword, which establishes a parent-child relationship between classes. Let's dive into a practical example to understand how class inheritance works in JavaScript.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Parent Class: Person
&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;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&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;The &lt;code&gt;Person&lt;/code&gt; class represents a basic entity with properties for name and age.&lt;/p&gt;

&lt;h3&gt;
  
  
  Derived Class: Teacher
&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;class&lt;/span&gt; &lt;span class="nc"&gt;Teacher&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_subject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_subject&lt;/span&gt;&lt;span class="p"&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;The &lt;code&gt;Teacher&lt;/code&gt; class extends the &lt;code&gt;Person&lt;/code&gt; class, inheriting its properties. It adds an additional property for the subject taught by the teacher.&lt;/p&gt;

&lt;h3&gt;
  
  
  Derived Class: Student
&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;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="err"&gt;= &lt;/span&gt;&lt;span class="nc"&gt;_class&lt;/span&gt;&lt;span class="p"&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;The &lt;code&gt;Student&lt;/code&gt; class also extends the &lt;code&gt;Person&lt;/code&gt; class and includes an extra property to represent the student's class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Instances
&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;person1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Manikandan&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&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;teacher1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Teacher&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Aravind&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DSA&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;student1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Nithish&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SSLC&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;We create instances of the &lt;code&gt;Person&lt;/code&gt;, &lt;code&gt;Teacher&lt;/code&gt;, and &lt;code&gt;Student&lt;/code&gt; classes, passing appropriate arguments to their constructors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="nx"&gt;person1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Person { name: 'Manikandan', age: 25 }&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="nx"&gt;teacher1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Teacher { name: 'Aravind', age: 22, subject: 'DSA' }&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="nx"&gt;student1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Student { name: 'Nithish', age: 24, class: 'SSLC' }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output demonstrates that each object correctly inherits properties from its parent class while also containing its specific properties.&lt;/p&gt;

&lt;p&gt;Conclusion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class inheritance in JavaScript provides a clean and structured way to establish relationships between classes, promoting code reuse and organization. &lt;/li&gt;
&lt;li&gt;By leveraging inheritance, developers can create more modular and maintainable codebases. In this example, we've seen how classes can be extended to model relationships such as teachers and students inheriting properties from a common parent class. &lt;/li&gt;
&lt;li&gt;Understanding and utilizing class inheritance is key to building robust and scalable JavaScript applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By mastering class inheritance, developers can unlock the full potential of object-oriented programming in JavaScript, enabling them to build complex and sophisticated applications with ease.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Classes in JavaScript: Explained OOP's in JS</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Fri, 22 Mar 2024 10:16:04 +0000</pubDate>
      <link>https://dev.to/nameismani/classes-in-javascript-explained-oops-in-js-29ia</link>
      <guid>https://dev.to/nameismani/classes-in-javascript-explained-oops-in-js-29ia</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Classes are a key feature of Object-Oriented Programming (OOP) in JavaScript, introduced in ECMAScript 2015 (ES6). They provide a more intuitive and structured way to define objects and their behavior. In this blog post, we'll delve into the concept of classes in JavaScript and demonstrate their usage through practical examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Classes:
&lt;/h3&gt;

&lt;p&gt;Classes in JavaScript act as blueprints for creating objects with predefined properties and methods. They encapsulate data and behavior within a single unit, making code organization and reuse easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exploring the Code:
&lt;/h3&gt;

&lt;p&gt;Let's break down the provided code snippet:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.  Class Declaration:&lt;/strong&gt; &lt;br&gt;
We declare a class named &lt;code&gt;Person&lt;/code&gt; using the &lt;code&gt;class&lt;/code&gt; keyword. This class represents a person and has a constructor method to initialize its properties &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt; when a new instance is created.&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="c1"&gt;// Class&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="c1"&gt;// Constructor with parameters&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&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;&lt;strong&gt;2. Creating an Instance:&lt;/strong&gt; &lt;br&gt;
We create a new instance of the &lt;code&gt;Person&lt;/code&gt; class using the &lt;code&gt;new&lt;/code&gt; keyword and passing "Manikandan" as the name and 25 as the age.&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;const&lt;/span&gt; &lt;span class="nx"&gt;person1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manikandan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Logging the Object:&lt;/strong&gt; &lt;br&gt;
We log the &lt;code&gt;person1&lt;/code&gt; object to the console, which displays the properties &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt; associated with it.&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="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="nx"&gt;person1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Person { name: 'Manikandan', age: 25 }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Defining a Class with Methods:&lt;/strong&gt; &lt;br&gt;
We declare a class named &lt;code&gt;Car&lt;/code&gt;, which represents a car. It has a constructor method to initialize its properties &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;color&lt;/code&gt;, along with a method &lt;code&gt;drive()&lt;/code&gt; to simulate driving the car.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="c1"&gt;// Constructor with parameters&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, This is My &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; car. And its color is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&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;&lt;strong&gt;5. Creating an Instance:&lt;/strong&gt; &lt;br&gt;
We create a new instance of the &lt;code&gt;Car&lt;/code&gt; class, passing "Rolls Royce" as the name and 'Black' as the color.&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;const&lt;/span&gt; &lt;span class="nx"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rolls Royce&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;Black&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;&lt;strong&gt;6. Logging the Object:&lt;/strong&gt; &lt;br&gt;
We log the &lt;code&gt;car1&lt;/code&gt; object to the console, which displays the properties &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;color&lt;/code&gt; associated with it.&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="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="nx"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Car { name: 'Rolls Royce', color: 'Black' }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Invoking a Method:&lt;/strong&gt; &lt;br&gt;
We invoke the &lt;code&gt;drive()&lt;/code&gt; method on the &lt;code&gt;car1&lt;/code&gt; object, which simulates driving the car and logs a message to the console.&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="nx"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hi, This is My Rolls Royce car. And its color is Black&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Classes in JavaScript provide a cleaner and more structured way to define objects and their behavior. By leveraging classes, you can create reusable and maintainable code, making it easier to build complex applications. In this blog post, we've explored the basics of using classes in JavaScript for Object-Oriented Programming.&lt;/p&gt;

&lt;p&gt;Stay tuned for more insights and advanced techniques in utilizing classes and OOP principles in JavaScript. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>closures in java script: A clear understand</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Thu, 21 Mar 2024 06:54:22 +0000</pubDate>
      <link>https://dev.to/nameismani/closures-in-javascript-4ocj</link>
      <guid>https://dev.to/nameismani/closures-in-javascript-4ocj</guid>
      <description>&lt;p&gt;In JavaScript, closures are a powerful and often misunderstood concept. They play a crucial role in maintaining data privacy, enabling functional programming patterns, and facilitating the creation of robust and modular code. In this article, we'll explore closures in-depth through a practical example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction to Closures:
&lt;/h3&gt;

&lt;p&gt;A closure is formed when a function retains access to its lexical scope even after the outer function has finished executing. This means that the inner function has access to variables and parameters of the outer function, even after the outer function has returned. Closures are a fundamental feature of JavaScript and are commonly used in various programming paradigms.&lt;/p&gt;

&lt;p&gt;Regarding this definition, don't panic. I can simplify it:) 😀&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Exploring Closure with Lexical Scoping
&lt;/h3&gt;

&lt;p&gt;Let's delve into a simple example to understand closures better:&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;function&lt;/span&gt; &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manikandan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printName&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, This is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;printName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// [Function: printName]&lt;/span&gt;
&lt;span class="nf"&gt;res&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;//  Hi, This is Manikandan.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Understanding the Example:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Function Declaration (&lt;code&gt;display&lt;/code&gt;):&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside the &lt;code&gt;display&lt;/code&gt; function, a variable &lt;code&gt;name&lt;/code&gt; is declared and assigned the value &lt;code&gt;"Manikandan"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Another nested function &lt;code&gt;printName&lt;/code&gt; is declared within &lt;code&gt;display&lt;/code&gt;. This function accesses the variable &lt;code&gt;name&lt;/code&gt; from its lexical scope.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Returning a Function:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;display&lt;/code&gt; function returns the &lt;code&gt;printName&lt;/code&gt; function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Function Execution:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;display()&lt;/code&gt; is called and its result is stored in &lt;code&gt;res&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;res&lt;/code&gt; now holds a reference to the &lt;code&gt;printName&lt;/code&gt; function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Closure in Action:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When &lt;code&gt;res()&lt;/code&gt; is invoked, it executes the &lt;code&gt;printName&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;Despite &lt;code&gt;display&lt;/code&gt; already finished executing, the &lt;code&gt;printName&lt;/code&gt; function still retains access to the &lt;code&gt;name&lt;/code&gt; variable due to closure.&lt;/li&gt;
&lt;li&gt;Thus, it successfully logs &lt;code&gt;Hi, This is Manikandan.&lt;/code&gt; to the console.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Explanation of Lexical Scoping:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Lexical scoping means that a function's scope is determined by its surrounding lexical context at the time of its definition.&lt;/li&gt;
&lt;li&gt;In our example, &lt;code&gt;printName&lt;/code&gt; is defined within the lexical scope of &lt;code&gt;display&lt;/code&gt;. Therefore, it has access to the variables defined within &lt;code&gt;display&lt;/code&gt;, including &lt;code&gt;name&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Even though &lt;code&gt;display&lt;/code&gt; finishes executing before &lt;code&gt;printName&lt;/code&gt; is called, &lt;code&gt;printName&lt;/code&gt; maintains a reference to the &lt;code&gt;name&lt;/code&gt; variable through closure, allowing it to access and use the variable's value.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Nested Function
&lt;/h2&gt;

&lt;p&gt;Absolutely! In JavaScript, closures extend to nested functions as well, allowing them to access variables from their containing scopes even if those scopes have finished executing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function display() {
    let name = "Manikandan";

    function printNaame() {
        let age = 25;

        function printAge() {
            console.log(`Hi this is ${name}, And My age is ${age}`)
        }

        return printAge;
    }

    return printNaame;
}

let res = display();  // [Function: printNaame]
let result = res();  // [Function: printAge]
result();

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

&lt;/div&gt;






&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Now Closure is, &lt;/p&gt;

&lt;p&gt;Inner function/nested function, whether it returns or not, will always have access to the outer scope variable. This is the concept of closures.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>call, bind, and apply Methods Unveiled in JavaScript</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Tue, 19 Mar 2024 07:21:02 +0000</pubDate>
      <link>https://dev.to/nameismani/exploring-javascript-call-bind-and-apply-methods-unveiled-3apm</link>
      <guid>https://dev.to/nameismani/exploring-javascript-call-bind-and-apply-methods-unveiled-3apm</guid>
      <description>&lt;h2&gt;
  
  
  &lt;u&gt;1. bind()&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;As per MDN,&lt;br&gt;
The bind() method of Function instances creates a new function that, when called, calls this function with its this keyword set to the provided value, and a given sequence of arguments preceding any provided when the new function is called.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting the Scene:&lt;/strong&gt;&lt;br&gt;
   Imagine we have a friend named "Manikandan" who loves coding. We want to create a special message function for him.&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;const&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;fname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manikandan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;kathiresan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, Welcome &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fname&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;getInfo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, This is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fname&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. I am from &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. I am  &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have this friend named &lt;code&gt;person&lt;/code&gt;, and we've given him some cool features like saying "hi" and telling us some information about himself.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Meet Another Friend:&lt;/strong&gt;
Now, let's meet another friend named "Aravind". He's also awesome, but we want to use the same special message function we made for Manikandan for Aravind too.
&lt;/li&gt;
&lt;/ol&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;person2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;fname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Aravind&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Kathiresan&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is our buddy &lt;code&gt;person2&lt;/code&gt;, who's a bit different from Manikandan but equally cool!&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Time to Use the Bind Magic:&lt;/strong&gt;
Here comes the exciting part! We're going to use something called the "bind" method to make our special message function work for Aravind too.
&lt;/li&gt;
&lt;/ol&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;bindMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person2&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="nx"&gt;bindMethod&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [Function: bound getInfo]&lt;/span&gt;
&lt;span class="nf"&gt;bindMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dindigul&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;Software Engineer&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the "bind" magic, we're basically saying, "Hey, make this special message function work for Aravind as well!"&lt;/li&gt;
&lt;li&gt;When we use &lt;code&gt;bindMethod&lt;/code&gt;, it's like using our special message function, but it's talking about Aravind instead of Manikandan!&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Let's Wrap It Up:&lt;/strong&gt;
So, what did we learn? The "bind" method helps us make cool functions and use them for different friends or things in our code. It's like making a superpower that we can share with anyone we want!&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;u&gt;2. call()&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;As described by the wise sages at MDN,&lt;br&gt;
The call() method of Function instances invokes the function and sets its this value to a provided value, along with any additional arguments passed to it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Setting Sail:&lt;/strong&gt;
Picture a valiant hero named "Manikandan", skilled in the art of coding. We're about to bestow upon him a powerful skill.
&lt;/li&gt;
&lt;/ol&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;hero&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manikandan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Greetings, fellow adventurer! I am &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;questInfo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objective&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Attention, brave souls! Our quest takes us to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;objective&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Behold our hero, &lt;code&gt;hero&lt;/code&gt;, with prowess in greeting fellow adventurers and sharing quest details.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Encountering a New Ally:&lt;/strong&gt;
Along our voyage, we meet a new ally named "Aravind". Equally brave, we wish to share our hero's abilities with this noble companion.
&lt;/li&gt;
&lt;/ol&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;ally&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Aravind&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Meet our ally, &lt;code&gt;ally&lt;/code&gt;, ready to embark on a different adventure.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Setting Course for Adventure:&lt;/strong&gt;
Prepare yourselves for a magical moment! We're invoking the call spell to share our hero's abilities with our new ally, along with specific parameters.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;hero&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;questInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ally&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mysterious Forest&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;uncover the ancient artifact&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the call spell, our hero extends his wisdom to our ally!&lt;/li&gt;
&lt;li&gt;As we invoke &lt;code&gt;hero.questInfo.call(ally, 'Mysterious Forest', 'uncover the ancient artifact')&lt;/code&gt;, our ally receives guidance tailored to their journey.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;u&gt;3. apply()&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;As described by the wise wizards at MDN,&lt;br&gt;
The apply() method of Function instances invokes the function and sets its this value to a provided value, along with an array or array-like object of arguments.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Setting Sail:&lt;/strong&gt;
Picture a valiant hero named "Manikandan", skilled in the art of coding. We're about to bestow upon him a powerful skill.
&lt;/li&gt;
&lt;/ol&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;hero&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Manikandan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Greetings, fellow adventurer! I am &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;questInfo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;objective&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Attention, brave souls! Our quest takes us to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;objective&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Behold our hero, &lt;code&gt;hero&lt;/code&gt;, with prowess in greeting fellow adventurers and sharing quest details.&lt;/li&gt;
&lt;/ul&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Encountering a New Ally:&lt;/strong&gt;
Along our voyage, we meet a new ally named "Aravind". Equally brave, we wish to share our hero's abilities with this noble companion.
&lt;/li&gt;
&lt;/ol&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;ally&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Aravind&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Meet our ally, &lt;code&gt;ally&lt;/code&gt;, ready to embark on a different adventure.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Setting Course for Adventure:&lt;/strong&gt;
Prepare yourselves for a magical moment! We're invoking the apply spell to share our hero's abilities with our new ally, along with specific parameters.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;hero&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;questInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ally&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;Mysterious Forest&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;uncover the ancient artifact&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;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the apply spell, our hero extends his wisdom to our ally!&lt;/li&gt;
&lt;li&gt;As we invoke &lt;code&gt;hero.questInfo.apply(ally, ['Mysterious Forest', 'uncover the ancient artifact'])&lt;/code&gt;, our ally receives guidance tailored to their journey.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;At Simply, &lt;br&gt;
&lt;strong&gt;Bind Method:&lt;/strong&gt; &lt;br&gt;
Employ bind to create a new function with a fixed this value, establishing a permanent connection between the function and its context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Call Method:&lt;/strong&gt;&lt;br&gt;
Use call to directly invoke a function with a specified this value, along with arguments, enabling method borrowing and flexible function invocation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Apply Method:&lt;/strong&gt;&lt;br&gt;
Utilize apply to invoke a function with a specified this value and &lt;strong&gt;an array of arguments&lt;/strong&gt;, facilitating dynamic parameter passing and versatile function invocation.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Constructor Functions in JavaScript 🤖</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Fri, 15 Mar 2024 11:06:14 +0000</pubDate>
      <link>https://dev.to/nameismani/exploring-constructor-functions-in-javascript-704</link>
      <guid>https://dev.to/nameismani/exploring-constructor-functions-in-javascript-704</guid>
      <description>&lt;h3&gt;
  
  
  ⚡ Introduction:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Constructor functions are a fundamental aspect of Object-Oriented Programming (OOP) in JavaScript. &lt;/li&gt;
&lt;li&gt;They allow us to create objects with predefined properties and methods. In this blog post, we'll explore the concept of constructor functions and how they can be used to create objects in JavaScript.&lt;/li&gt;
&lt;li&gt;Simply, Constructor function as &lt;strong&gt;template&lt;/strong&gt;.  This template is used for &lt;strong&gt;creating an object&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ Understanding Constructor Functions:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Constructor functions are special functions in JavaScript used to create and initialize objects. &lt;/li&gt;
&lt;li&gt;They serve as blueprints for creating multiple instances of objects with shared properties and methods.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ⚡ Exploring the Code:
&lt;/h3&gt;

&lt;p&gt;Let's break down the code snippet you provided:&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;function&lt;/span&gt; &lt;span class="nf"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&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="s2"&gt;`Hi, Welcome &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&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;&lt;strong&gt;Function Declaration:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We declare a function named &lt;code&gt;Person&lt;/code&gt; , which serves as our constructor function. &lt;/li&gt;
&lt;li&gt;It takes two parameters: &lt;code&gt;_name&lt;/code&gt;  and &lt;code&gt;_age&lt;/code&gt; , representing the name and age of a person.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Initializing Properties:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside the constructor function, we use the &lt;code&gt;this&lt;/code&gt; keyword to create properties &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt; for each instance of the &lt;code&gt;Person&lt;/code&gt; object. &lt;/li&gt;
&lt;li&gt;The values of these properties are set based on the arguments passed to the constructor function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Adding a Method:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;We define a method named &lt;code&gt;greet&lt;/code&gt; within the constructor function. This method allows each &lt;code&gt;Person&lt;/code&gt; object to greet with a personalized message.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ Instance Creation
&lt;/h2&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;person1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Manikandan&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating an Instance:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;We create a new instance of the &lt;code&gt;Person&lt;/code&gt; object using the &lt;code&gt;new&lt;/code&gt; keyword, passing 'Manikandan' as the name and 25 as the age.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logging the Object:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;We log the &lt;code&gt;person1&lt;/code&gt; object to the console, which displays the properties and methods associated with it.&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="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="nx"&gt;person1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Person Person { name: 'Manikandan', age: 25, greet: [Function (anonymous)] }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Invoking the Method:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;We invoke the &lt;code&gt;greet&lt;/code&gt; method on the &lt;code&gt;person1&lt;/code&gt; object, which logs a personalized greeting message to the console.&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="nx"&gt;person1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Hi, Welcome Manikandan&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ⚡ Conclusion:
&lt;/h3&gt;

&lt;p&gt;Constructor functions are essential in JavaScript for creating objects with predefined properties and methods. They provide a convenient way to structure and organize code in an Object-Oriented manner. By understanding constructor functions, you'll be better equipped to leverage the power of OOP in your JavaScript projects.  Happy coding..!🧑🏻‍💻&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>OOP's JavaScript: Object-Oriented Programming Paradigm 👽 👾</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Thu, 14 Mar 2024 12:14:02 +0000</pubDate>
      <link>https://dev.to/nameismani/exploring-object-oriented-programming-oop-in-javascript-44e0</link>
      <guid>https://dev.to/nameismani/exploring-object-oriented-programming-oop-in-javascript-44e0</guid>
      <description>&lt;h2&gt;
  
  
   Introduction: 
&lt;/h2&gt;

&lt;p&gt; &lt;br&gt;
Object-oriented programming is a computer programming model that organizes software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior.&lt;/p&gt;

&lt;p&gt;JavaScript is not actually an object-oriented language, but we can write object-oriented code by using something called a prototype object.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Objects:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In JavaScript, objects are fundamental entities that represent real-world entities, concepts, or functionalities. &lt;/li&gt;
&lt;li&gt;They encapsulate data (properties) and behavior (methods) within a single unit. Objects can be created using object literals, constructor functions, or classes in modern JavaScript.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Encapsulation:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Encapsulation is the bundling of data and methods that operate on that data into a single unit, known as an object. &lt;/li&gt;
&lt;li&gt;It hides the internal state of an object and exposes only the necessary functionalities, promoting code organisation and modularity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Inheritance:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Inheritance is a mechanism that allows objects to inherit properties and methods from other objects. It promotes code reuse and establishes hierarchical relationships between objects. &lt;/li&gt;
&lt;li&gt;In JavaScript, inheritance is achieved through prototype-based inheritance, where objects inherit from other objects through their prototype chains.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Polymorphism:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Polymorphism enables objects to take on different forms or respond differently to the same method of invocation. It fosters flexibility and extensibility in code design. &lt;/li&gt;
&lt;li&gt;In JavaScript, polymorphism is achieved through dynamic method binding and the ability to override methods inherited from prototypes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Abstraction:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Abstraction involves hiding complex implementation details and exposing only the essential features of an object. &lt;/li&gt;
&lt;li&gt;It allows developers to work at a higher level of abstraction without worrying about the internal complexities, promoting code readability and maintainability.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Object-oriented programming in JavaScript provides a structured approach to building scalable and maintainable applications. By embracing OOP principles such as encapsulation, inheritance, polymorphism, and abstraction, developers can write more organised and efficient code.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next installment, where we'll dive into encapsulation by exploring how it keeps your code organised and secure using a simple example involving a coffee machine. Until then, happy coding! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>👨‍💻 Splice method in JavaScript : Unveiling the Magic of JavaScript Arrays</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Fri, 01 Mar 2024 07:13:36 +0000</pubDate>
      <link>https://dev.to/nameismani/unveiling-the-magic-of-javascript-arrays-a-deep-dive-into-the-splice-method-kfk</link>
      <guid>https://dev.to/nameismani/unveiling-the-magic-of-javascript-arrays-a-deep-dive-into-the-splice-method-kfk</guid>
      <description>&lt;p&gt;In the vast landscape of JavaScript, arrays reign supreme as indispensable tools for data manipulation. Among the myriad methods available for array manipulation, one stands out as the cornerstone of versatility and power: the splice() method. In this article, we embark on a journey to uncover the secrets and nuances of this exceptional method, exploring its ability to create, delete, and update elements within arrays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is splice()?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The splice() method adds and/or removes array elements.&lt;/li&gt;
&lt;li&gt;The splice() method overwrites the original array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;syntax&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;array.splice(start)&lt;br&gt;
array.splice(start, deleteCount)&lt;br&gt;
array.splice(start, deleteCount, item1)&lt;br&gt;
array.splice(start, deleteCount, item1, item2)&lt;br&gt;
array.splice(start, deleteCount, item1, item2, ...itemN)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating, Deleting, and Updating with Ease&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether you want to add something new, remove the old, or update what's already there, splice() has got you covered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Adding Elements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Say you have an array of names and you want to add a new one to it. With splice(), you can do that without breaking a sweat.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Updating Elements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sometimes you just need to freshen things up a bit. With splice(), you can easily swap out old data for new, keeping your array looking sharp.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Deleting Elements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maybe you've got too many items in your array, or some of them are just no longer needed. splice() can help you get rid of them in a snap.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Insert element&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = ['Manikandan', 'Aradvind', 'Kathiresan', 'Susila'];
console.log(name) 
// [ 'Manikandan', 'Aradvind', 'Kathiresan', 'Susila' ]


// CREATE
name.splice(name.length, 1, "Vignesh");
console.log(name) 
// [ 'Manikandan', 'Aradvind', 'Kathiresan', 'Susila', 'Vignesh' ]

// UPDATE
name.splice(1, 1, "Aravind");
console.log(name)
// [ 'Manikandan', 'Aravind', 'Kathiresan', 'Susila', 'Vignesh' ]


// DELETE
name.splice(0,1);
console.log(name)
// [ 'Aradvind', 'Kathiresan', 'Susila', 'Vignesh' ]



// INSERT INBETWEEN
name.splice(3, 0, "Siva");
console.log(name)
// [ 'Aradvind', 'Kathiresan', 'Susila', 'Siva', 'Vignesh' ]


// INSERT START
name.splice(0, 0, "Aswin");
console.log(name)
// [ 'Aswin', 'Aradvind', 'Kathiresan', 'Susila', 'Siva', 'Vignesh' ]

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When it comes to working with arrays in JavaScript, splice() is the method you'll want to have in your toolkit. Its ability to create, delete, and update elements makes it a true powerhouse for data manipulation. So next time you find yourself wrangling with arrays, remember the magic of splice() and let it work its wonders for you.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>React memo - Performance Optimization</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Mon, 19 Feb 2024 07:18:04 +0000</pubDate>
      <link>https://dev.to/nameismani/react-memo-4kdi</link>
      <guid>https://dev.to/nameismani/react-memo-4kdi</guid>
      <description>&lt;p&gt;&lt;strong&gt;React.memo(Component)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Performance optimization is an important factor in web development.&lt;br&gt;
React.memo as a higher-order component used for optimizing functional components by memoizing their output.&lt;br&gt;
React uses “memoization” as an optimization technique to speed up the rendering process of the components. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React.memo() was introduced with React 16.6 to avoid unnecessary re-renders in functional components.&lt;/li&gt;
&lt;li&gt; It is a higher-order component that accepts another component as a prop. &lt;/li&gt;
&lt;li&gt;It will only render the component if there is any change in the props.&lt;/li&gt;
&lt;li&gt;Here, the parent renders again anytime I make a change to its state in the parent component. A child is also rendered again. However, there are no modifications or effects for youngsters. Extraneous rework.&lt;/li&gt;
&lt;/ul&gt;

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

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

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

&lt;p&gt;Here, the parent renders again anytime I make a change to its state in the parent component. A child is also rendered again. However, there are no modifications or effects for youngsters. Extraneous rework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React.memo(ChildComponent)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My child component is wrapped to React.memo (child) in this instance. It is therefore rendered only when my props for this child change.&lt;/p&gt;

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

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

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>JavaScript Single thread</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Wed, 14 Feb 2024 11:19:11 +0000</pubDate>
      <link>https://dev.to/nameismani/javascript-single-thread-54p3</link>
      <guid>https://dev.to/nameismani/javascript-single-thread-54p3</guid>
      <description>&lt;p&gt;JavaScript is a &lt;strong&gt;synchronous&lt;/strong&gt;, &lt;strong&gt;blocking&lt;/strong&gt;, &lt;strong&gt;single-threaded&lt;/strong&gt; language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Synchronous&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Synchronously means that the programmer is executed line by line.&lt;/li&gt;
&lt;li&gt;In JavaScript, synchronous is a behavior where tasks are executed one after another in a top-down approach.&lt;/li&gt;
&lt;li&gt;That means each task must wait for the previous one's completion.&lt;/li&gt;
&lt;li&gt;In other words, synchronous code executes sequentially, and if a task takes a long time to complete, it can block the execution of subsequent tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Blocking&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It refers to blocking further or next functions or operations until the current task is finished.**&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Single thread&lt;/strong&gt;&lt;br&gt;
 You know how, when you're trying to juggle multiple tasks at work or at home, you can only focus on one thing at a time?  You might be writing an email, and you can't start another task until you hit send. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;That's how JavaScript works too—it can only do one thing at a time. &lt;/li&gt;
&lt;li&gt;If it's busy doing something like fetching data from a server or animating a web-page, it can't do anything else until it's finished.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Task Start");

function someFunction() {
  console.log("First Execution");
  console.log("Second Execution");
}

someFunction();

console.log("Task End");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

&lt;p&gt;&lt;strong&gt;summary&lt;/strong&gt;&lt;br&gt;
when a function like someFunction() is executed synchronously, it means that the JavaScript code will run step by step, in order. &lt;br&gt;
So, when someFunction() is called, the program won't move on to the next line (console.log("Task End")) until someFunction() finishes running all its code.&lt;/p&gt;

&lt;h2&gt;
  
  
  But how multi thread / Non-Blocking?
&lt;/h2&gt;

&lt;p&gt;JavaScript nature behavior is single thread. But Yes, it's possible to achieve concurrency in JavaScript using techniques like Web Workers in web browsers and Worker Threads in Node.js. These mechanisms allow you to run JavaScript code in separate threads, enabling concurrent execution and improving performance for certain tasks. While JavaScript itself remains single-threaded in its core, these technologies provide a way to leverage multi-threading capabilities in JavaScript environments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Controlled vs Uncontrolled Components in React</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Thu, 01 Feb 2024 10:17:03 +0000</pubDate>
      <link>https://dev.to/nameismani/controlled-vs-uncontrolled-components-in-react-2a1p</link>
      <guid>https://dev.to/nameismani/controlled-vs-uncontrolled-components-in-react-2a1p</guid>
      <description>&lt;p&gt;&lt;strong&gt;Controlled vs Uncontrolled Component&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;&lt;strong&gt;Controlled Component:&lt;/strong&gt; &lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a controlled component, form data is handled by a React 
component - (state)&lt;/li&gt;
&lt;li&gt;The internal state (not react state) is not maintained.&lt;/li&gt;
&lt;li&gt;Validation is easy.&lt;/li&gt;
&lt;li&gt;Controlled by the parent component.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';

const ControlledComponent = () =&amp;gt; {
    const [name, setName] = useState("");
    const handleChange = (e) =&amp;gt; {
        setName(e.target.value)
    };

    const handleSubmit = () =&amp;gt; {
        alert(name)
    }

    return (
        &amp;lt;&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
                &amp;lt;label&amp;gt;Name&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" value={name} onChange={handleChange} /&amp;gt;
                &amp;lt;button type='submit'&amp;gt;Submit&amp;lt;/button&amp;gt;
            &amp;lt;/form&amp;gt;
        &amp;lt;/&amp;gt;
    )
}

export default ControlledComponent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;strong&gt;Uncontrolled Component:&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uncontrolled component, form data is handled by a 
DOM Element - (ref)&lt;/li&gt;
&lt;li&gt;Internal state maintained.&lt;/li&gt;
&lt;li&gt;Validation is much more complex.&lt;/li&gt;
&lt;li&gt;Controlled by DOM itself.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useRef } from 'react'

const UncontrolledComponent = () =&amp;gt; {
    const inputRef = useRef(null);

    const handleSubmit = () =&amp;gt; {
        alert(inputRef.current.value)
    }

    return (
        &amp;lt;&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
                &amp;lt;label&amp;gt;Name&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" ref={inputRef} /&amp;gt;
                &amp;lt;button type='submit'&amp;gt;Submit&amp;lt;/button&amp;gt;
            &amp;lt;/form&amp;gt;
        &amp;lt;/&amp;gt;
    )
}

export default UncontrolledComponent

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

&lt;/div&gt;



</description>
      <category>react</category>
      <category>component</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>State vs Props in React</title>
      <dc:creator>Manikandan K</dc:creator>
      <pubDate>Thu, 01 Feb 2024 06:31:41 +0000</pubDate>
      <link>https://dev.to/nameismani/state-vs-props-in-react-4kk0</link>
      <guid>https://dev.to/nameismani/state-vs-props-in-react-4kk0</guid>
      <description>&lt;p&gt;&lt;strong&gt;State&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; The state is a built-in React object / that is used to contain 
data or information /about the component&lt;/li&gt;
&lt;li&gt; State is Mutable (changeable)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";

const App = () =&amp;gt; {
  // here defined name as a state variable
  const [name, setName] = useState('Manikandan');
  return &amp;lt;h2&amp;gt;Hi, I am {name}. &amp;lt;/h2&amp;gt;
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Props&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Props allow you to pass data / from one component to other components / as an argument.&lt;/li&gt;
&lt;li&gt;Props are  immutable (not changeable)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";

const App = () =&amp;gt; {
  const [name, setName] = useState('Manikandan');
  // here pass the (name state) to the Display component as props
  return &amp;lt;Display name={name} /&amp;gt;
}

const Display = (props) =&amp;gt; {
  // Here receive the name as props
  // we can use (props) or ({name})
  return &amp;lt;h2&amp;gt;Hi, I am {props.name}. &amp;lt;/h2&amp;gt;
}

export default App;

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

&lt;/div&gt;



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