<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Parathan Thiyagalingam - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Parathan Thiyagalingam - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 17 May 2026 22:28:01 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/parathantl/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Object Oriented Programming Concepts: How to go from Zero to One with Objects ]]>
                </title>
                <description>
                    <![CDATA[ Object Oriented Programming is one of the most widely used programming paradigms. The name itself defines how it works. “Object Oriented” - the Object plays an important role. Manipulating objects and getting the results is the ultimate goal of Objec... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/object-oriented-concepts/</link>
                <guid isPermaLink="false">66baefcfff91e9c03fcb30aa</guid>
                
                    <category>
                        <![CDATA[ Blogging ]]>
                    </category>
                
                    <category>
                        <![CDATA[ coding ]]>
                    </category>
                
                    <category>
                        <![CDATA[ freeCodeCamp.org ]]>
                    </category>
                
                    <category>
                        <![CDATA[ object oriented ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Object Oriented Programming ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Parathan Thiyagalingam ]]>
                </dc:creator>
                <pubDate>Wed, 07 Aug 2019 19:09:25 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca108740569d1a4ca4c46.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Object Oriented Programming is one of the most widely used programming paradigms. The name itself defines how it works. “Object Oriented” - the Object plays an important role. Manipulating objects and getting the results is the ultimate goal of Object Oriented Programming.</p>
<p>The languages that use Object Oriented Programming paradigms are known as Object Oriented Programming Languages. They are mostly high level languages such as</p>
<ol>
<li>Java</li>
<li>C#</li>
<li>Python - Python is both a Scripted/Structured &amp; Object Oriented Language</li>
</ol>
<p>To program in Object Oriented Programming, concepts called “<strong>Object Oriented Concepts</strong>” are used. These concepts simplify &amp; add more value to Object Oriented Programming.</p>
<p>Those concepts are</p>
<ol>
<li>Encapsulation</li>
<li>Abstraction</li>
<li>Polymorphism</li>
<li>Inheritance</li>
</ol>
<p>Before moving into these concepts, we need to know about Class &amp; Objects.</p>
<p><strong>An Object</strong> is the basic run-time entity in OOP. In our day-today life we see a lot of objects like a television, mobile phone, dog, humans, cars &amp; other living and non-living objects. These can be portrayed as objects in OOP.</p>
<p><strong>A Class</strong> is a blueprint or prototype that defines variables/properties and methods/functions common to all objects of a certain kind. It's a logical component.</p>
<p>Simply said, Class is a <strong>user-defined</strong> data type. Objects are <strong>variables</strong> of a Class. Once the Class has been created we can create as many Objects as we want.</p>
<p>For example, take a class named Tree. State/properties of the Tree class are:</p>
<ul>
<li>Name of the tree</li>
<li>Age of the tree</li>
<li>Type of the tree</li>
<li>Height of the tree</li>
</ul>
<p>State/properties are used to define the attributes of an object.</p>
<p>That is, <strong>State/properties/attributes</strong> all represents the same thing.</p>
<p>Behaviors of the Tree can be:</p>
<ul>
<li>Giving fruit</li>
<li>Falling of leaves</li>
<li>Absorbing water from roots to the upper parts</li>
<li>Creating shadows</li>
</ul>
<p>Then, Mango is a variable of Class Tree. We can store and retrieve all the properties &amp; behaviors we defined for the class Tree by creating an object of Mango.</p>
<p>Syntax for Creating an object of Mango from class Tree:</p>
<p>                                                <strong>Tree</strong> Mango;</p>
<h3 id="heading-encapsulation">Encapsulation</h3>
<p>Have you ever used a tablet/medicine which encapsulated by a colored cover?</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/pills_tablets_medicine_capsule_heal_drugs_pharmacy_nutrient_additives-859474.jpg-d.jpeg" alt="Image" width="600" height="400" loading="lazy">
<em>Medicines are encapsulated &amp; placed inside the tablet</em></p>
<p>Inside that medicine is kept safely. We can't find anything with our naked eye. To see what's inside we need to open up that cover....</p>
<p>Similarly, all the <strong>data members (variables,attributes/properties)</strong> &amp; <strong>behaviors(functions/methods)</strong> are gathered together and closed. Class is a best example for Encapsulation.</p>
<p>For an instance,</p>
<p>You are going to the pharmacy to buy prescribed medicines for you. You handover the prescription to the pharmacist and then he/she will take the medicine from the store &amp; give you the bill.</p>
<p>In this scenario,</p>
<p>Medicines - act as variables or properties or attributes</p>
<p>Pharmacist - act as member function/method where he/she helps in giving you the        medicine</p>
<p>You - external application or another software code</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/Screenshot-from-2019-08-20-22-13-54.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>By using Encapsulation, <strong>data can be restricted</strong> from the usage of the outside world. The function defined in the class only can access the properties. This can be defined at the implementation stage. Programmers can define and specify the accessibility of the member variables while under development rather than making all the variables global like in procedural languages. This controlling of accessibility is also known as <strong>Information hiding</strong>.</p>
<p>Encapsulation <strong>allows to expose the necessary things and hiding the important things from the outside world</strong>. So, the hidden parts of a class acts like <strong>Encapsulation</strong> &amp; the exposed parts acts like <strong>Abstraction</strong>.</p>
<h3 id="heading-abstraction">Abstraction</h3>
<p>Exposing necessary features of a class <strong>without explaining much or details</strong> is done by Abstraction.</p>
<p>Today morning I wanted to make a hot tea and I used a water kettle to boil the water. I just turned on the <strong>On</strong> button to start boil water. I don’t want to know the inner workflow of the kettle where it has high resistance and that resistance produces heat and boils the water. Instead, I have to fulfill my work easily. Therefore, having this On button to boil the water is known as Abstraction.</p>
<p>Similarly, we can take a remote controller which helps in manipulating TV operation using simple keys in the remote.</p>
<p><strong>Data abstraction</strong> is a programming technique that depends on the separation of <strong>interface</strong> and <strong>implementation</strong>.</p>
<p>This data abstraction can be archived from using 2 different classes while coding using OOP</p>
<ol>
<li>Abstraction class:  (0-100)% abstraction</li>
<li>Interface class:  100% abstraction</li>
</ol>
<h3 id="heading-inheritance">Inheritance</h3>
<p>The word itself describe what its functionality. Everyone has their inheritance qualities from their birth. You could have your grandparents/ your parents qualities from your birth. This is what Inheritance does in OOP.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/Screenshot-from-2019-08-20-22-14-01.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>A class can have properties &amp; methods of its parent class. Additionally the class can have its own properties and methods too. The parent class is called as <strong>base class</strong>. The class that inherits base class is called as <strong>derived class</strong>. Inheritance is the most powerful feature of OOP.</p>
<p>By using Inheritance effectively we could save a lot of time and reduce the errors in our program. This causes us to <strong>increase the quality of work</strong> and <strong>productivity</strong>.</p>
<p>There are different types of Inheritance</p>
<ol>
<li>Single Inheritance</li>
<li>Hierarchical Inheritance</li>
<li>Multiple Inheritance</li>
<li>Multi Level Inheritance</li>
</ol>
<h3 id="heading-polymorphism">Polymorphism</h3>
<p>Polymorphism is a <strong>Greek</strong> term which refers to the ability of taking more than one form / overloading.</p>
<p>Say for example we all know about <strong>functions</strong> in programming. They take different arguments inside parenthesis. Polymorphism is nothing but with the same function name, different arguments passed to get the result.</p>
<p>For e.g :- function called sum can take 2 arguments or 3 arguments.</p>
<p>                                    sum(3,4)  sum(10,23,56)<br>Calling these functions by providing suitable number of parameters will give the result according to how the called function has designed.</p>
<p><strong><em>How the program distinguish which function need to be executed at the above scenario?</em></strong></p>
<p>There is a feature called <strong>Dynamic binding</strong> in OOP. This will call the actual function according to the program execution. When the program runs the function with 2 arguments compiler takes the two argument functions to execute the program similarly for 3 arguments too.</p>
<p>Until the run-time, compiler won’t know exactly which function need to be invoked. It depends on the way the program calls the function name. This is also be known as <strong>Late binding.</strong></p>
<h3 id="heading-uses-of-object-oriented-concepts">Uses of Object Oriented Concepts</h3>
<ul>
<li>Data can be hidden from outside using <strong>Encapsulation</strong> (Information hiding)</li>
<li>Code can be reused by using <strong>Inheritance</strong></li>
<li>Operators/methods.functions can be overloaded by using <strong>Polymorphism</strong>. I.e: same function or operator name can be used for multi-tasking</li>
<li>Data abstraction can be archived from <strong>Abstraction</strong>.</li>
<li>Project migrations are easy (can be converted to larger size from smaller size)</li>
<li>Partitioning the works for same project</li>
<li>Manageable software complexity</li>
</ul>
<h3 id="heading-areas-of-application-of-oop">Areas of application of OOP</h3>
<ol>
<li>AI and expert systems</li>
<li>Enterprise applications</li>
<li>Neural Network and parallel programming</li>
<li>Office automation systems</li>
</ol>
<p>Hope you enjoyed a brief introduction to Object Oriented Concepts by reading. I hope to write how can we program Object Oriented Programming in my upcoming posts too.</p>
<hr>
<p>Please send you feedback about my article to parathan19@gmail.com</p>
<p><a target="_blank" href="https://www.linkedin.com/in/parathantl/">LinkedIn</a> | <a target="_blank" href="http://twitter.com/parathantl">Twitter</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ A basic guide to Closures in JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ The Closure is a collection of all variables in scope at the time of function creation. To use closure, create a function inside another function which is called a Nested Function. The inner function will have access to the variables in the outer fun... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/a-basic-guide-to-closures-in-javascript-9fc8b7e3463e/</link>
                <guid isPermaLink="false">66baefc6ed87d1ed72d74174</guid>
                
                    <category>
                        <![CDATA[ ES6 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Parathan Thiyagalingam ]]>
                </dc:creator>
                <pubDate>Fri, 03 May 2019 18:47:26 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*Nm0GW5PgM1okjXAZz_aQrQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The Closure is a collection of all variables in scope at the time of function creation. To use closure, create a function inside another function which is called a Nested Function. The inner function will have access to the variables in the outer function scope (<strong>Closure</strong> helps to access the outer function scope), even after the outer function has returned. Closures are created every time a function is created.</p>
<p>Before moving on to understand about Closures, let’s first get the big picture about Scope Chain in JavaScript.</p>
<p>Normally, there are 2 types of scope:</p>
<ul>
<li>Global Scope</li>
<li>Local Scope</li>
</ul>
<p>In ES5 version, a variable inside a function is not visible outside. But variables inside a block (conditions like if or while) are visible outside too.</p>
<p>From this, ES5 has function scope. There is no block scope.</p>
<blockquote>
<p>Edited on: 9th May 2019</p>
<p>According to <strong>ES5</strong>, using functions were the only way to declare a block scope in code.</p>
<p>But, in ES6 it was eased by <strong>let</strong> &amp; <strong>const</strong> keywords which provides block scope.</p>
<p>Anyhow, Its better to have a knowledge on how JavaScript evolved step by step.</p>
</blockquote>
<p>Lets continue this in ES5 version :</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">app</span>(<span class="hljs-params"></span>)</span>{
   <span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span>;
   <span class="hljs-built_in">console</span>.log(a); <span class="hljs-comment">// 10</span>
   <span class="hljs-built_in">console</span>.log(b); <span class="hljs-comment">// 2</span>
}
<span class="hljs-built_in">console</span>.log(b); <span class="hljs-comment">//   ReferenceError: b is not defined</span>
app();
</code></pre>
<p>As we already know, <strong>a</strong> is a Global variable &amp; <strong>b</strong> is a local variable which is <strong>specific</strong> to the app function.</p>
<p>We can’t get the value of a local variable out of the local scope.</p>
<h4 id="heading-using-a-nested-function-function-inside-a-function">Using a Nested Function — Function inside a Function</h4>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">app</span>(<span class="hljs-params"></span>)</span>{
     <span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span>;
     <span class="hljs-keyword">var</span> d = <span class="hljs-number">3</span>;
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params"></span>)</span>{
     <span class="hljs-keyword">var</span> c = a + b;
   }
 <span class="hljs-keyword">return</span> add;
}
<span class="hljs-keyword">var</span> x = app();
<span class="hljs-built_in">console</span>.dir(x);
</code></pre>
<p>Here, the app is the parent function &amp; add function is the child function.</p>
<ul>
<li>Rather than using console.log, <strong>console.dir</strong> is used to console all the properties of a specified JavaScript object which helps developers get the properties of that object</li>
<li>Variable x is assigned to app function &amp; the app function returns the add function. Therefore we could see all the object properties of the add function.</li>
</ul>
<p>If you see the console in the browser, you could see the Closure object inside the Scopes array.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/QT8fuXZHAuL9OPxS3M2v7nI2hF7c4rX1zt3U" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Since the inner <strong>function add</strong> accesses the outer function variables <strong>b &amp; d</strong>, those 2 variables will be added to the Closure object for the reference.</p>
<p>Let’s have look at the next example for Closure:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>;
<span class="hljs-keyword">var</span> startFunc;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">app</span>(<span class="hljs-params"></span>)</span>{
      <span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span>;
   <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params"></span>)</span>{
      <span class="hljs-keyword">var</span> c = a + b;
      <span class="hljs-built_in">console</span>.log(c);
   }
   startFunc = add();
}
app(); <span class="hljs-comment">// Invoke the app function</span>
startFunc; 
<span class="hljs-comment">// as the app function invoked above will assign the add function to startFunc &amp; console the value of c</span>
</code></pre>
<ul>
<li>a Global function called startFunc is assigned to the add function which is a child function of the parent app function.</li>
<li>This is possible only after the app function is invoked, otherwise startFunc will act as a global variable without any value assigned</li>
</ul>
<h4 id="heading-application-of-closures-in-javascript">Application of Closures in JavaScript</h4>
<p>Most of us use Closures while coding but we don’t get why we are using it. JavaScript doesn’t have the access modifiers like <strong>private, public, protected</strong> like other Object Oriented Programming Languages. So, we have to use functions to protect the namespace from the outside code usage in ES5.</p>
<p>Especially in functions, <strong>Immediately-invoked Function Expression (IIFE)</strong> is the one which is executed immediately after the declaration. You don’t need to invoke the function after the function is declared.</p>
<p>IIFE enables to write <strong>Module Pattern</strong> (one of the Design Pattern) in JavaScript.</p>
<p>Syntax definition of IIFE is:</p>
<pre><code>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
             <span class="hljs-comment">//variables &amp; scope that inside the function </span>
})();
</code></pre><p>Let’s have an example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> studnetEnrollment = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">//private variables which no one can change</span>
    <span class="hljs-comment">//except the function declared below.</span>
     <span class="hljs-keyword">var</span> count = <span class="hljs-number">0</span>;
     <span class="hljs-keyword">var</span> prefix = <span class="hljs-string">"S"</span>;
    <span class="hljs-comment">// returning a named function expression</span>
     <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">innerFunc</span>(<span class="hljs-params"></span>) </span>{
         count = count + <span class="hljs-number">1</span>;
         <span class="hljs-keyword">return</span> prefix + count;
     };
 <span class="hljs-keyword">return</span> innerFunc;
})();
<span class="hljs-keyword">var</span> x = studnetEnrollment(); <span class="hljs-comment">// S1</span>
<span class="hljs-built_in">console</span>.log(x);
<span class="hljs-keyword">var</span> y = studnetEnrollment(); <span class="hljs-comment">// S2 </span>
<span class="hljs-built_in">console</span>.log(y);
</code></pre>
<p>count &amp; prefix are the 2 private variables which can’t be changed by anyone &amp; can only be accessible to the inner function (here its innerFunc). This access is possible only by the feature called Closure.</p>
<ul>
<li>At the first time, when the studentEnrollment function is called, the count variable inside the function is incremented 1 by innerFunc function.</li>
<li>At the second time, the count is incremented the previous value of count which is 1 to 2</li>
<li>These are possible by the Closure feature.</li>
</ul>
<h4 id="heading-conclusion">Conclusion</h4>
<p>The Closure is a collection of variables in an outer function which gives access to the inner function scope to protect the global namespace.</p>
<p>Closures enable developers to write clean code like OOP Languages which doesn’t confuse the global &amp; local variable names in ES5 version.</p>
<p>Happy Coding…….!!!!!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to build a Rest API with Spring Boot using MySQL and JPA ]]>
                </title>
                <description>
                    <![CDATA[ Hi Everyone! For the past year, I have been learning JavaScript for full-stack web development. For a change, I started to master Java — the powerful Object Oriented Language. In that case, I found a very clean and elegant framework called Spring Boo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-rest-api-with-spring-boot-using-mysql-and-jpa-f931e348734b/</link>
                <guid isPermaLink="false">66baefc9ff91e9c03fcb30a8</guid>
                
                    <category>
                        <![CDATA[ Java ]]>
                    </category>
                
                    <category>
                        <![CDATA[ MySQL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ spring-boot ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Parathan Thiyagalingam ]]>
                </dc:creator>
                <pubDate>Fri, 15 Mar 2019 16:25:55 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca447740569d1a4ca6173.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hi Everyone! For the past year, I have been learning JavaScript for full-stack web development. For a change, I started to master Java — the powerful Object Oriented Language.</p>
<p>In that case, I found a very clean and elegant framework called Spring Boot to build a back end.</p>
<p>Previously, in JavaScript development, I used:</p>
<ol>
<li>Mongoose — an ORM (Object Relational Mapping) for Mongo DB</li>
<li>Sequelize — an ORM for MySQL</li>
</ol>
<p>For Java-related development, there are lot of ORM’s like <strong>Hibernate, JPA</strong> (Java Persistence API) &amp; <strong>Java Object Oriented Querying.</strong></p>
<p>I choose to build with JPA which is traditionally used in Java applications.</p>
<p>It was very interesting, and took about one week to finish as I had to learn Spring Boot (There are a lot of annotations “<strong>@</strong>” and other cool kinds of stuff to learn), JPA, and Hibernate along the way.</p>
<p>All this magic is mostly done by the <strong>annotations</strong> (“<strong>@</strong>” symbol) used in Spring Boot.</p>
<h4 id="heading-creating-a-spring-boot-maven-project">Creating a Spring Boot Maven Project</h4>
<p>Let’s create a Spring Boot Maven Project Application using this <a target="_blank" href="https://start.spring.io/">link</a>.</p>
<p>“<strong>Maven</strong>” is a project management tool used to manage dependency management. It’s just like Node Package Manager (<strong>NPM</strong>) in the JS development environment.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/YsUiOp9T6nTFMyBPE2ZaGPQbMnmzddx2v3sU" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We have <strong>package.json in NodeJS</strong> for dependency management and <strong>pom.xml in Spring Boot</strong> for dependency management.</p>
<p>In Group, write whatever the name you want. Usually, the domain name of the organization is written right to left.</p>
<p>For example our domain name is <a target="_blank" href="http://www.javaAPI.com">www.javaAPI.com</a>, so the group name could be <strong>com.javaAPI.www</strong></p>
<p>Then in the Artifact type the <strong>name of the folder you want</strong>.</p>
<p>On the right side, add the following dependencies:</p>
<ol>
<li>WEB — To use the dependencies of Spring (The older framework of Spring Boot used to develop web applications)</li>
<li>JPA — Java Persistence API</li>
<li>MYSQL</li>
</ol>
<p>Then click “Generate Project”. You will find a rar file — extract it. Then open that folder in your favorite IDE.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/u3sdwjDkrp1ua8vM4vRVFLbX545YJ9IPbABj" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Click on the <strong>com.rest.API</strong> and you will find an <strong>ApiApplication.java</strong> file as follows:</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.rest.API;
<span class="hljs-keyword">import</span> org.springframework.boot.SpringApplication;
<span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;
<span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ApiApplication</span> </span>{
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
      SpringApplication.run(ApiApplication.class, args);
   }
}
</code></pre>
<p>This code is enough to start your server. Normally spring boot runs on <strong>localhost:8080</strong>.</p>
<p>Type in your terminal as follows:</p>
<blockquote>
<p><strong>mvn spring-boot:run</strong></p>
</blockquote>
<p>See your localhost running in the web browser at port 8080. It looks blank as we haven’t done anything yet.</p>
<h4 id="heading-lets-explore-the-files-and-their-tags">Let’s explore the files and their tags</h4>
<p>If you have a look at the pom.xml file you may notice that the dependencies you put in when creating the application in Spring Initialize like MySQL, JPA, and Web will be inside a <strong>&lt;dependen</strong>cy&gt; tag.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zHV02AMHLVCjin9mlAZh4lbwigWVk98mYeFF" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The starter and tester dependencies are the core for creating the Spring Boot Application to serve on the server.</p>
<p>Now, let’s move to APIApplication.java which is the main file.</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.rest.API;
<span class="hljs-keyword">import</span> org.springframework.boot.SpringApplication;
<span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;
<span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ApiApplication</span> </span>{
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
      SpringApplication.run(ApiApplication.class, args);
   }
}
</code></pre>
<p>Here the name of the package is in the first line of the code. Using that package name, you can import any class, method, or instances in another package file.</p>
<p>After that, two modules are imported from “org.springframework.boot” package.</p>
<ol>
<li>SpringApplication</li>
<li>SpringBootApplication</li>
</ol>
<p>Since Spring boot is the latest application developing framework of Spring, it needs the packages of Spring Application as well as its specific packages.</p>
<p>After that <strong>@SpringBootApplication</strong> Annotation is used. This Annotation consists of annotation which is used in Spring:</p>
<ol>
<li><strong>@Component</strong> — Tells the compiler that the following class is a component which should be included when compiling the whole application.</li>
<li><strong>@ComponentScan</strong> — This one does the Scan of which packages we are going to use in the following Java class.</li>
<li><strong>@EnableAutoConfiguration</strong> — enables Spring Boot’s autoconfiguration mechanism to import important modules for the Spring Boot to run.</li>
</ol>
<p>These are the annotations used to start the Spring Boot Application to run on a server.</p>
<p>Here is an article I have written about <a target="_blank" href="https://medium.com/@parathanlive123/annotation-their-uses-in-java-4285c9413365">Annotation &amp; their uses in Java</a>.</p>
<h3 id="heading-lets-create-model-for-our-data">Let’s create Model for our data</h3>
<p>Let’s create a Model class to save, retrieve, update and delete the details of a book.</p>
<p>For that, I have to create a new package named <strong>model</strong> and inside that creating a <strong>Book.java</strong> class to put my code.</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.rest.API.model;
<span class="hljs-keyword">import</span> javax.persistence.*;
<span class="hljs-keyword">import</span> javax.validation.constraints.NotBlank;
<span class="hljs-meta">@Entity</span>
<span class="hljs-meta">@Table(name = "books")</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Book</span> </span>{
    <span class="hljs-meta">@Id</span>
    <span class="hljs-meta">@GeneratedValue</span>
    <span class="hljs-keyword">private</span> Long id;
<span class="hljs-meta">@NotBlank</span>
    <span class="hljs-keyword">private</span> String book_name;
<span class="hljs-meta">@NotBlank</span>
    <span class="hljs-keyword">private</span> String author_name;
<span class="hljs-meta">@NotBlank</span>
    <span class="hljs-keyword">private</span> String isbn;
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Book</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">super</span>();
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Book</span><span class="hljs-params">(Long id, String book_name, String author_name, String isbn)</span> </span>{
        <span class="hljs-keyword">super</span>();
        <span class="hljs-keyword">this</span>.id = id;
        <span class="hljs-keyword">this</span>.book_name = book_name;
        <span class="hljs-keyword">this</span>.author_name = author_name;
        <span class="hljs-keyword">this</span>.isbn=isbn;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> Long <span class="hljs-title">getId</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> id;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setId</span><span class="hljs-params">(Long id)</span> </span>{
        <span class="hljs-keyword">this</span>.id = id;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getBook_name</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> book_name;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setBook_name</span><span class="hljs-params">(String book_name)</span> </span>{
        <span class="hljs-keyword">this</span>.book_name = book_name;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getAuthor_name</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> author_name;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setAuthor_name</span><span class="hljs-params">(String author_name)</span> </span>{
        <span class="hljs-keyword">this</span>.author_name = author_name;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getIsbn</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> isbn;
    }
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setIsbn</span><span class="hljs-params">(String isbn)</span> </span>{
        <span class="hljs-keyword">this</span>.isbn = isbn;
    }
}
</code></pre>
<p>Here I’m using JPA (Java Persistence API) which is a collection of classes and methods to continuously store data into a database.</p>
<p><strong>@Entity</strong> — used to denote that this class is going to be an Entity in the database.</p>
<p><strong>@Table</strong> — which takes some values like the name you are going to name your table</p>
<p><strong>@Id</strong> — denotes that the id is the primary key / identifying key for this table</p>
<p><strong>@NotBlank —</strong> is used to say that these attributes should not be blank.</p>
<p>Other than that there is an empty constructor which has a super method to satisfy the JPA customs. Getter and setter methods are usually in a POJO class (<strong>Plain old Java object</strong>).</p>
<h3 id="heading-creating-the-repository">Creating the Repository</h3>
<p>Next, we are going to create a <strong>repository</strong> package to deal with database management in Java.</p>
<p>Create an Interface called <strong>BookRepository.java</strong> inside the <strong>repository</strong> package.</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.rest.API.repository;
<span class="hljs-keyword">import</span> com.rest.API.model.Book;
<span class="hljs-keyword">import</span> org.springframework.data.jpa.repository.JpaRepository;
<span class="hljs-keyword">import</span> org.springframework.stereotype.Repository;
<span class="hljs-meta">@Repository</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">BookRepository</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">JpaRepository</span>&lt;<span class="hljs-title">Book</span>, <span class="hljs-title">Long</span>&gt; </span>{
}
</code></pre>
<p>I have imported the <strong>JpaRepository</strong> package to use that repository in the <strong>BookRepository</strong> interface by connecting my most recently coded Book model to do <strong>CRUD</strong> operations.</p>
<p>There are already built-in methods in those repositories to do CRUD operations.</p>
<p>Eg:</p>
<pre><code class="lang-java">.findAll() - to get All datas
.save()    - to save the got Data
.delete()  - to delete the data
</code></pre>
<p>Inside the &lt;&gt; tag we are taking the Model name we are going to use and the Primary key’s datatype.</p>
<p><strong>@Repository</strong>: Annotation used to Indicate the DAO (<strong>Data Access Object</strong>) component in the persistence layer.</p>
<p>It tells the compiler that the interface is going to use the Repository to do database activities.</p>
<h4 id="heading-creating-controller-and-exception-handling">Creating Controller and Exception Handling</h4>
<p>Create a new package called <strong>controller,</strong> and inside that create a <strong>BookController.java</strong> file which contains the endpoints.</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.rest.API.controller;

<span class="hljs-keyword">import</span> com.rest.API.exception.BookNotFoundException;
<span class="hljs-keyword">import</span> com.rest.API.model.Book;
<span class="hljs-keyword">import</span> com.rest.API.repository.BookRepository;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.*;
<span class="hljs-keyword">import</span> org.springframework.http.ResponseEntity;
<span class="hljs-keyword">import</span> javax.validation.Valid;
<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-meta">@RestController</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BookController</span> </span>{

<span class="hljs-meta">@Autowired</span>
    BookRepository bookRepository;

<span class="hljs-comment">// Get All Notes</span>
    <span class="hljs-meta">@GetMapping("/books")</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;Book&gt; <span class="hljs-title">getAllNotes</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> bookRepository.findAll();
    }

<span class="hljs-comment">// Create a new Note</span>
    <span class="hljs-meta">@PostMapping("/books")</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Book <span class="hljs-title">createNote</span><span class="hljs-params">(<span class="hljs-meta">@Valid</span> <span class="hljs-meta">@RequestBody</span> Book book)</span> </span>{
        <span class="hljs-keyword">return</span> bookRepository.save(book);
    }

<span class="hljs-comment">// Get a Single Note</span>
    <span class="hljs-meta">@GetMapping("/books/{id}")</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Book <span class="hljs-title">getNoteById</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(value = "id")</span> Long bookId)</span> <span class="hljs-keyword">throws</span> BookNotFoundException </span>{
        <span class="hljs-keyword">return</span> bookRepository.findById(bookId)
                .orElseThrow(() -&gt; <span class="hljs-keyword">new</span> BookNotFoundException(bookId));
    }

<span class="hljs-comment">// Update a Note</span>
    <span class="hljs-meta">@PutMapping("/books/{id}")</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Book <span class="hljs-title">updateNote</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable(value = "id")</span> Long bookId,
                           <span class="hljs-meta">@Valid</span> <span class="hljs-meta">@RequestBody</span> Book bookDetails)</span> <span class="hljs-keyword">throws</span> BookNotFoundException </span>{

Book book = bookRepository.findById(bookId)
                .orElseThrow(() -&gt; <span class="hljs-keyword">new</span> BookNotFoundException(bookId));

book.setBook_name(bookDetails.getBook_name());
        book.setAuthor_name(bookDetails.getAuthor_name());
        book.setIsbn(bookDetails.getIsbn());

Book updatedBook = bookRepository.save(book);

<span class="hljs-keyword">return</span> updatedBook;
    }

<span class="hljs-comment">// Delete a Note</span>
    <span class="hljs-meta">@DeleteMapping("/books/{id}")</span>
    <span class="hljs-keyword">public</span> ResponseEntity&lt;?&gt; deleteBook(<span class="hljs-meta">@PathVariable(value = "id")</span> Long bookId) <span class="hljs-keyword">throws</span> BookNotFoundException {
        Book book = bookRepository.findById(bookId)
                .orElseThrow(() -&gt; <span class="hljs-keyword">new</span> BookNotFoundException(bookId));

bookRepository.delete(book);

<span class="hljs-keyword">return</span> ResponseEntity.ok().build();
    }
}
</code></pre>
<p>The first imported package is for the Book Not Found exception (for which we are going to create a file in a bit).</p>
<p><strong>Explanation of Annotations we used here:</strong></p>
<ol>
<li><strong>RestController:</strong> This annotation is used to denote every method in the annotated class as Domain Object.</li>
</ol>
<p>So what is Domain Object…?</p>
<p>It simply says that Domain Object == Business Object.</p>
<p>They are usually represented by entities and value objects related to the endpoint we are giving to get the data from the database.</p>
<ol start="2">
<li><strong>Autowired</strong>: This annotation is used to wire the bean classes automatically.</li>
</ol>
<p>For that, you need to know about “<strong>What is a bean Class..?</strong>”</p>
<p>Basically, a Java Bean Class is a simple class which encapsulates many objects into it.</p>
<p>This is an article I wrote on <a target="_blank" href="https://medium.com/@parathantl/java-bean-class-804c6431a57f">Java Bean Classes</a>.</p>
<p>The following are the Mapping Annotations for the endpoints to perform CRUD Operations.</p>
<ol start="3">
<li><strong>GetMapping:</strong> This is an <strong>interface</strong> which contains the path of the endpoint to perform a Get method. This GetMapping interface uses the RequestMapping interface which can have the “path, value, params, headers” method to perform the Get method in earlier Spring versions.</li>
</ol>
<p>Now it’s simplified by using <strong>GetMapping.</strong></p>
<ol start="4">
<li><p><strong>PostMapping</strong>: This is an <strong>interface</strong> which contains the path of the endpoint to perform the Post method.</p>
</li>
<li><p><strong>PutMapping:</strong> This is an <strong>interface</strong> which contains the path of the endpoint to perform the Put method to Update.</p>
</li>
<li><p><strong>DeleteMapping:</strong> This is an <strong>interface</strong> which contains the path of the endpoint to perform the Delete method.</p>
</li>
</ol>
<p>In the final lines, you probably noticed the “<strong>ResponseEntity</strong>” keyword.</p>
<p>What is <strong>that</strong>…??</p>
<p>It’s a Java class which inherits <strong>HttpEntity</strong> class to manipulate the HTTP Responses. Whether the request of the connection is “<strong>OK</strong>” or if there are any problems, throw an <strong>exception</strong> from the <strong>HttpEntity</strong> class.</p>
<p><strong>orElseThrow():</strong> This is a method found in the <strong>Optional class in Java8</strong> which was introduced to handle Exceptions. The optional class provides various utility methods to check the presence or absence of an object, which helps to deal with NullPointerException.</p>
<p><strong>orElseThrow</strong> is a method that Returns value if present, otherwise invokes an exception.</p>
<h4 id="heading-creating-a-notfoundexception-if-there-is-no-such-bookid">Creating a NotFoundException if there is no such book_id</h4>
<p>As orElseThrow method throws a NotFound Exception. The following is the Exception Handling part. Create a <strong>BookNotFoundException.java</strong> file inside exception package.</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.rest.API.exception;
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BookNotFoundException</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Exception</span> </span>{
<span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> book_id;
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">BookNotFoundException</span><span class="hljs-params">(<span class="hljs-keyword">long</span> book_id)</span> </span>{
        <span class="hljs-keyword">super</span>(String.format(<span class="hljs-string">"Book is not found with id : '%s'"</span>, book_id));
        }
}
</code></pre>
<p>The created class extends the Superclass of Exception. In the constructor, I’m passing the book_id &amp; prints the exception.</p>
<p>So, that’s it…</p>
<p>We have finished the REST API part. Now you can build the app (which was explained in Part 1) and do some Testings with Postman.</p>
<h4 id="heading-connecting-with-mysql-database">Connecting with MySql Database</h4>
<p>Inside the <strong>application.properties</strong> of your <strong>resources</strong> folder, add the following:</p>
<pre><code class="lang-java">## <span class="hljs-function">Spring <span class="hljs-title">DATASOURCE</span> <span class="hljs-params">(DataSourceAutoConfiguration &amp; DataSourceProperties)</span>
spring.datasource.url </span>= jdbc:mysql:<span class="hljs-comment">//localhost:3306/library</span>
spring.datasource.username = root <span class="hljs-comment">//normally put your MySQL username </span>
spring.datasource.password = YOUR_MYSQL_PASSWORD
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL <span class="hljs-keyword">for</span> the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# <span class="hljs-function">Hibernate ddl <span class="hljs-title">auto</span> <span class="hljs-params">(create, create-drop, validate, update)</span>
spring.jpa.hibernate.ddl-auto </span>= update
</code></pre>
<p>That’s it.</p>
<p>We have built a basic REST API in Spring Boot. Congrats!</p>
<p>If anything is wrong or need to be corrected, please let me know in the comments section.</p>
<p>Get in touch with me on <a target="_blank" href="https://twitter.com/Parathantl">twitter</a>.</p>
<p>Happy Coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Let’s explore Slice(), Splice() & Spread Syntax(…) in JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ I came across this freeCodeCamp challenge and got stuck for some time thinking about how I could find a way to solve it. They already mentioned solving using Slice & Splice. I was confused at that time when to use Slice and when to use Splice. Here, ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/lets-explore-slice-splice-spread-syntax-in-javascript-e242a6f21e60/</link>
                <guid isPermaLink="false">66baefcc90ea1057a46fdfa6</guid>
                
                    <category>
                        <![CDATA[ coding ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ES6 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Parathan Thiyagalingam ]]>
                </dc:creator>
                <pubDate>Fri, 25 Jan 2019 16:43:18 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*btQyN4AbhZ-RWQQser8y5A.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>I came across this <a target="_blank" href="https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice">freeCodeCamp</a> challenge and got stuck for some time thinking about how I could find a way to solve it. They already mentioned solving using Slice &amp; Splice. I was confused at that time when to use Slice and when to use Splice.</p>
<p>Here, I’m gonna share how I solved it with those methods.</p>
<p>Both Slice and Splice are used to manipulate arrays. Let’s see how they do it.</p>
<h3 id="heading-slice">Slice:</h3>
<p>The Slice method takes 2 arguments.</p>
<p><strong>1st Argument</strong>: Specifies from where the selection should be started.</p>
<p>For Example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">5</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
arr1.slice(<span class="hljs-number">1</span>); <span class="hljs-comment">// [5,8,9]</span>
</code></pre>
<p>From the first index (5) it will return the elements.</p>
<p><strong>2nd Argument</strong>: Specifies at which level the endpoint should be. If you didn’t put this in the parenthesis while calling the slice method, it will return the elements from the starting index to the end of the array.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">5</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
<span class="hljs-built_in">console</span>.log(arr1.slice(<span class="hljs-number">1</span>,<span class="hljs-number">3</span>));
<span class="hljs-comment">//[ 5, 8 ]</span>
</code></pre>
<p>If you put a negative number while calling, the selection will be selected from the end of the array.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">5</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
<span class="hljs-built_in">console</span>.log(arr1.slice(<span class="hljs-number">-2</span>));
<span class="hljs-comment">//[ 8, 9 ]</span>
</code></pre>
<p><strong>Note: Slice always returns the selected elements from the array.</strong></p>
<p><strong>Slice won’t change the array. The array remains intact. See the below Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">5</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
arr1.slice(<span class="hljs-number">2</span>);
<span class="hljs-built_in">console</span>.log(arr1);
<span class="hljs-comment">// [ 1, 5, 8, 9 ]</span>
</code></pre>
<p>Even if you made some changes to the array it won’t affect it. It will return the original array as it is at the start.</p>
<h3 id="heading-splice"><strong>Splice:</strong></h3>
<p>It can take multiple arguments.</p>
<p>That means,</p>
<p><strong>1st Argument</strong>: Specifies at which position a new element or existing element should be added/removed. If the value is negative the position will be counted from the end of the array.</p>
<p><strong>2nd Argument</strong>: The numbers of elements to be removed from the starting position. If it is 0, then no elements will be removed. If it is not passed, it will delete all elements from the starting position.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">5</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
<span class="hljs-built_in">console</span>.log(arr1.splice(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>));
<span class="hljs-comment">// [ 5, 8 ]</span>
</code></pre>
<p><strong>3rd Argument -&gt;nth Argum</strong>ent: The value of the items you want to add to the array.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">5</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
<span class="hljs-built_in">console</span>.log(arr1.splice(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-string">'Hi'</span>,<span class="hljs-string">'Medium'</span>));
<span class="hljs-comment">// [5,8]</span>
</code></pre>
<p>You may think that we have added ‘Hi’,’Medium’ to the array but it doesn't show here…. Right?</p>
<p>Yes, we have consoled the <strong>arr1.splice(1,2,’Hi’,’Medium’).</strong></p>
<p><strong>Note:</strong></p>
<ul>
<li><strong>Splice will return removed elements from the array only.</strong></li>
<li><strong>Splice will change the original array</strong></li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">5</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
arr1.splice(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-string">'Hi'</span>,<span class="hljs-string">'Medium'</span>);
<span class="hljs-built_in">console</span>.log(arr1);
<span class="hljs-comment">// [ 1, 'Hi', 'Medium', 9 ]</span>
</code></pre>
<h3 id="heading-spread-syntax"><strong>Spread Syntax:</strong></h3>
<p><strong>Definition</strong>: Allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.</p>
<p>Let's have an example for this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">3</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>];
<span class="hljs-keyword">var</span> arr2 = [<span class="hljs-number">5</span>,arr1,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
<span class="hljs-built_in">console</span>.log(arr2);
<span class="hljs-comment">// [ 5, [ 1, 3, 6, 7 ], 8, 9 ]</span>
</code></pre>
<p>I want this to be in a single array like <strong>[ 5, 1, 3, 6, 7, 8, 9 ].</strong></p>
<p>I can use this Spread Syntax to solve this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">3</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>];
<span class="hljs-keyword">var</span> arr2 = [<span class="hljs-number">5</span>,...arr1,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
<span class="hljs-built_in">console</span>.log(arr2);
<span class="hljs-comment">//[ 5, 1, 3, 6, 7, 8, 9 ]</span>
</code></pre>
<p>Another main use of Spread Syntax is while copying an array:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">var</span> arr2 = arr;
arr2.push(<span class="hljs-number">4</span>);

<span class="hljs-built_in">console</span>.log(arr2);
<span class="hljs-comment">// [ 1, 2, 3, 4 ]</span>

<span class="hljs-built_in">console</span>.log(arr);
<span class="hljs-comment">// [ 1, 2, 3, 4 ]</span>
</code></pre>
<p>I added “<strong>4</strong>” to <strong>arr2</strong> only. But it made the change to arr also.</p>
<p>We can solve this using the Spread Syntax as follows...</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">var</span> arr2 = [...arr]; <span class="hljs-comment">// like arr.slice()</span>
arr2.push(<span class="hljs-number">4</span>);

<span class="hljs-built_in">console</span>.log(arr2);
<span class="hljs-comment">// [ 1, 2, 3, 4 ]</span>

<span class="hljs-built_in">console</span>.log(arr);
<span class="hljs-comment">// [ 1, 2, 3]</span>
</code></pre>
<p>You may refer to the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">MDN</a> documentation for more info about Spread Syntax.</p>
<p><strong>So, let’s have a look at the challenge.</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">frankenSplice</span>(<span class="hljs-params">arr1, arr2, n</span>) </span>{

<span class="hljs-comment">// It's alive. It's alive!</span>

<span class="hljs-keyword">let</span> array2Copy = [...arr2];

array2Copy.splice(n,<span class="hljs-number">0</span>, ...arr1);

             <span class="hljs-comment">//console.log(array2Copy);</span>

<span class="hljs-keyword">return</span> array2Copy;

}

frankenSplice([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>], <span class="hljs-number">1</span>);
</code></pre>
<p>The main condition of this challenge is “should not alter arr1/arr2 after function has executed”.</p>
<p>So, created a <strong>copy array of arr2,</strong> and <strong>using the splice</strong> <strong>method</strong> add the arr1 inside the arr2’s copy which is named as <strong>array2Copy.</strong></p>
<h4 id="heading-final-conclusion"><strong>Final Conclusion:</strong></h4>
<p>-&gt;Slice method will</p>
<ul>
<li>return the selected elements from the array</li>
<li>take 2 arguments</li>
<li>not alter the original array</li>
</ul>
<p>-&gt;Splice method will</p>
<ul>
<li>return the removed elements of the array</li>
<li>take multiple arguments</li>
<li>alters the original array</li>
</ul>
<p>This is my first ever tutorial about coding — thanks for reading! Your feedback will help me to shape up my coding &amp; writing skill.</p>
<p>Happy Coding…!</p>
<p>Connect with me through <a target="_blank" href="https://twitter.com/parathantl">Twitter</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
