<?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: Sushanta Gupta</title>
    <description>The latest articles on DEV Community by Sushanta Gupta (@sushantagupta007).</description>
    <link>https://dev.to/sushantagupta007</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%2F818724%2F074703d5-a730-4545-9ca3-390757a68321.jpeg</url>
      <title>DEV Community: Sushanta Gupta</title>
      <link>https://dev.to/sushantagupta007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sushantagupta007"/>
    <language>en</language>
    <item>
      <title>Closure, A Confused topic</title>
      <dc:creator>Sushanta Gupta</dc:creator>
      <pubDate>Wed, 01 Jun 2022 15:42:38 +0000</pubDate>
      <link>https://dev.to/sushantagupta007/closurea-confused-topic-396k</link>
      <guid>https://dev.to/sushantagupta007/closurea-confused-topic-396k</guid>
      <description>&lt;p&gt;The closure was really a scary topic for me. Fortunately, I found the video of Namste Javascript  [(&lt;a href="https://www.youtube.com/watch?v=qikxEIxsXco)%5Dof"&gt;https://www.youtube.com/watch?v=qikxEIxsXco)]of&lt;/a&gt; the closure concept and I believe I understand closure. &lt;/p&gt;

&lt;p&gt;First let's observe the following code block&lt;br&gt;
`&lt;br&gt;
function outer () {&lt;br&gt;
    let a = 5; &lt;br&gt;
    function inner (){&lt;br&gt;
        console.log("From Inner",a)&lt;br&gt;
    }&lt;br&gt;
    return inner; &lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;const myFunc = outer(); &lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Here, the outer function is returning the inner function. We are assigning the returned result of the outer function to the myFunc variable. There is nothing new till this point. &lt;/p&gt;

&lt;p&gt;However, what happens when we assign the returned result of the outer function. If we console.log myFunc we will see the following result. &lt;br&gt;
&lt;code&gt;&lt;br&gt;
ƒ inner (){&lt;br&gt;
        console.log("From Inner",a)&lt;br&gt;
    }&lt;br&gt;
&lt;/code&gt; &lt;br&gt;
But if we call the myFunc() then, we get the result 5. How is it possible? &lt;/p&gt;

&lt;p&gt;The question is how inner function gets the value of a, which is declared in its parent scope? &lt;/p&gt;

&lt;p&gt;The answer is when the inner function is returned, then not only the function is returned but also the variable is returned. This is called closure. &lt;br&gt;
Imagine this way, &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GL1Qu9hD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2t9hlyyyfe51450s14cm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GL1Qu9hD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2t9hlyyyfe51450s14cm.PNG" alt="imagine closure in this way" width="328" height="128"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So a closure is like an envelope/box that contains a function and the variables required for the function. &lt;/p&gt;

&lt;p&gt;Simply, closure is a function along with lexical scope bundled together. &lt;br&gt;
Hope you have understood the closure concept. &lt;br&gt;
Thanks for reading. To make me inspired, please write your feedback in the comment section. &lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>How to send and receive data in Socket IO?</title>
      <dc:creator>Sushanta Gupta</dc:creator>
      <pubDate>Mon, 25 Apr 2022 00:55:30 +0000</pubDate>
      <link>https://dev.to/sushantagupta007/how-to-send-and-receive-data-in-socket-io-emj</link>
      <guid>https://dev.to/sushantagupta007/how-to-send-and-receive-data-in-socket-io-emj</guid>
      <description>&lt;p&gt;Socket.io is a library to abstract the WebSocket connections. According to the official website of socket io, Socket.IO is a library that enables low-latency, bidirectional and event-based communication between a client and a server.&lt;/p&gt;

&lt;p&gt;What does it mean by event-based? We can send and receive data in Socket by using the following code block. We can send an event from the server and receive it in the client and vice-versa. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To Receive Data&lt;/strong&gt;&lt;br&gt;
socket.on("message", (hello) =&amp;gt; {&lt;br&gt;
  console.log(hello); // world&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To send Data&lt;/strong&gt;&lt;br&gt;
 socket.emit("message", "hello");&lt;/p&gt;

&lt;p&gt;In general, the code for sending and receiving data is &lt;br&gt;
Receiving Data: socket.on(eventName, listenerFn)&lt;br&gt;
Sending Data : socket.emit(eventName, Data) &lt;/p&gt;

&lt;p&gt;We have to use same eventName for sending and catching data. There are some pre-defined events in Socket Io but we can also make our own custom events provided that the same event name is to be used in both client and server. &lt;/p&gt;

</description>
      <category>programming</category>
      <category>socketio</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Simple Overview of testing</title>
      <dc:creator>Sushanta Gupta</dc:creator>
      <pubDate>Wed, 13 Apr 2022 20:31:44 +0000</pubDate>
      <link>https://dev.to/sushantagupta007/simple-overview-of-testing-1aj</link>
      <guid>https://dev.to/sushantagupta007/simple-overview-of-testing-1aj</guid>
      <description>&lt;p&gt;In the application development cycle, Testing is an integral part. It is a process of checking whether our code works expectedly or not. Although we can do manual checking of our code, it is not a recommended way. We need a pre-built system to test our code appropriately. In addition, testing saves our time and also improves our code. &lt;/p&gt;

&lt;p&gt;The steps for testing an application are as follows:&lt;br&gt;&lt;br&gt;
Code &amp;gt; Outcome &amp;gt; Test &amp;gt; If (Success) ? “Go for production”: If(failure)?  Make a change in the code&lt;/p&gt;

&lt;p&gt;There are different kinds of tests available for us. They are unit tests, Integration tests, and E2E tests. Generally, we have to write thousand of unit testing codes. Compare to unit testing, the number of integration tests is smaller. Among the three, we should write a few e2e testing. &lt;/p&gt;

</description>
      <category>mocha</category>
      <category>jest</category>
      <category>testing</category>
    </item>
    <item>
      <title>Easy Explanation of Reduce Function</title>
      <dc:creator>Sushanta Gupta</dc:creator>
      <pubDate>Wed, 23 Feb 2022 09:32:37 +0000</pubDate>
      <link>https://dev.to/sushantagupta007/easy-explanation-of-reducer-function-p9i</link>
      <guid>https://dev.to/sushantagupta007/easy-explanation-of-reducer-function-p9i</guid>
      <description>&lt;p&gt;Suppose we have an array of numbers, which is denoted by &lt;code&gt;let A= [1,2,3]&lt;/code&gt;. We want to find the total of all array elements. In this case, we can use for loop.But we we may also use reduce function. We may also use the &lt;code&gt;array.prototype.reduce&lt;/code&gt; function to do this task.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;array.reduce&lt;/code&gt; function takes two arguments. One is a callBack function and other is initial value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myArray.reduce(callBack,initialvalue)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This callback function takes four arguments-previousvalue, current value,currentIndex, Array. The first two arguments are required, and the last two are optional.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const callBack = (
previousvalue, //required
currentvalue, //required
currentIndex, //optional
Array //optional
)=&amp;gt;{
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myArray = [1,2,3]
const myFunc = (previous,current)=&amp;gt;{
return previous+current
}

const result = myArray.reduce(myFunc,0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final result will be 6, but this result is dependent on the initial value. &lt;/p&gt;

&lt;p&gt;We will try to understand why this result is dependent on the initial value. As there are three elements, reduce method will iterate three times.&lt;br&gt;
In the first iteration, the previous-value and current-value is zero and one respectively. Finally, its sum is be stored in the total value. In the next iteration, the total value becomes the previous value, and the current value is the next array element, and its total is stored at the total variable. Thus the loop continues until the last array element. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1-P-WTUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdqbef5wiksuv7h7k0qw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1-P-WTUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdqbef5wiksuv7h7k0qw.PNG" alt="iteration" width="604" height="148"&gt;&lt;/a&gt;            &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Absolute Position vs Relative Position in CSS</title>
      <dc:creator>Sushanta Gupta</dc:creator>
      <pubDate>Mon, 21 Feb 2022 01:59:16 +0000</pubDate>
      <link>https://dev.to/sushantagupta007/absolute-position-vs-relative-position-4ci1</link>
      <guid>https://dev.to/sushantagupta007/absolute-position-vs-relative-position-4ci1</guid>
      <description>&lt;p&gt;When I started learning web development, some topics confused me. Among them, CSS positioning was one of them. I invested a certain amount of time for a clear idea about this topic. What I have understood, I will write in the following paras. I will not use any technical jargon and try to avoid complexity. &lt;/p&gt;

&lt;p&gt;We find two kinds of positions in CSS-absolute and relative. &lt;br&gt;
&lt;strong&gt;Relative Position:&lt;/strong&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7X7C34N1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjy9fc273rfya5h4avrc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7X7C34N1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjy9fc273rfya5h4avrc.png" alt="Three Divs" width="263" height="123"&gt;&lt;/a&gt;&lt;br&gt;
Supposer, there are four divs, and these divs are denoted by 1, 2,3, and 4. The first, second, and third div is smaller, and the fourth is larger. Larger div surround the smaller div. &lt;br&gt;
HTML markup is given below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
        .innerDiv{
            border:1px solid black;
            height:60px;
            width:60px;
            display:inline-block;
        }
        .outerDiv{
            padding:2rem;
            width:300px;
            height:120px;
            border:1px solid red;
            display:inline-block;
        }     
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="outerDiv"&amp;gt; 
        &amp;lt;div id="" class="innerDiv"&amp;gt; Button 1 &amp;lt;/div&amp;gt; &amp;lt;!--Number 1--&amp;gt;
        &amp;lt;div class="innerDiv"&amp;gt; Button 2 &amp;lt;/div&amp;gt; &amp;lt;!--Number 2--&amp;gt;
        &amp;lt;div class="innerDiv"&amp;gt; Button 3 &amp;lt;/div&amp;gt; &amp;lt;!--Number 3--&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will get the following figure if we look at the browser. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jNEIDrhp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/man62bbmijg0bmge6j24.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jNEIDrhp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/man62bbmijg0bmge6j24.PNG" alt="How we get in the browser" width="385" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we add id (#relative) to Number three div and add CSS inside the style tag. &lt;br&gt;
&lt;strong&gt;Relative Position&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;style&amp;gt;
        .innerDiv{
            border:1px solid black;
            height:60px;
            width:60px;
            display:inline-block;
        }
        .outerDiv{
            padding:2rem;
            width:300px;
            height:120px;
            border:1px solid red;
            display:inline-block;
        }   
        #relative{
            position:relative;
            top:60px;   
        }  
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="outerDiv"&amp;gt; 
        &amp;lt;div id="" class="innerDiv"&amp;gt; Button 1 &amp;lt;/div&amp;gt; &amp;lt;!--Number 1--&amp;gt;
        &amp;lt;div class="innerDiv"&amp;gt; Button 2 &amp;lt;/div&amp;gt; &amp;lt;!--Number 2--&amp;gt;
        &amp;lt;div id="relative "class="innerDiv"&amp;gt; Button 3 &amp;lt;/div&amp;gt; &amp;lt;!--Number 3--&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the third div moves downward from its place. But the third div does not leave any space in the current position. Hence, other component does not change their location.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SOvrftcC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lz4xx6pyimg5f0chclgi.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SOvrftcC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lz4xx6pyimg5f0chclgi.PNG" alt="Relative Position of Third Div" width="420" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Absolute Position&lt;/strong&gt;&lt;br&gt;
Now we add id (#absolute) to the third div and add CSS inside the style tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
        .innerDiv{
            border:1px solid black;
            height:60px;
            width:60px;
            display:inline-block;
        }
        .outerDiv{
            width:300px;
            height:119px;
            display:inline-block;
            box-sizing: border-box;
        }
        #absolute{
            position:absolute;
            top:60px;   
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class="outerDiv"&amp;gt; 
        &amp;lt;div  class="innerDiv"&amp;gt; Button 1 &amp;lt;/div&amp;gt;
        &amp;lt;div class="innerDiv"&amp;gt; Button 2 &amp;lt;/div&amp;gt;
        &amp;lt;div id="absolute" class="innerDiv"&amp;gt; Button 3 &amp;lt;/div&amp;gt; &amp;lt;!--Number 3--&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the outerDiv has no position then, the third div uses the document body and moves along with the body. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z06ADCtj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dm8bl86izqshbwh0tbb0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z06ADCtj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dm8bl86izqshbwh0tbb0.PNG" alt="Absolute Position and nearest unpositioned ancestor" width="381" height="182"&gt;&lt;/a&gt;&lt;br&gt;
If the outerDiv has a relative position, then the third div uses this div and moves in reference with this div. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CFUlNv3p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4dtkh51bx8vpxkckm24.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CFUlNv3p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4dtkh51bx8vpxkckm24.PNG" alt="Absolute Position" width="380" height="175"&gt;&lt;/a&gt;&lt;br&gt;
You can see a subtle difference between the above two images. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/css/css_positioning.asp"&gt;According to w3school, An element with position: absolute; is positioned relative to the nearest positioned ancestor. &lt;br&gt;
However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling. &lt;/a&gt;&lt;/p&gt;

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