<?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: Devraj Sawant</title>
    <description>The latest articles on DEV Community by Devraj Sawant (@devrajsawant).</description>
    <link>https://dev.to/devrajsawant</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3409821%2F239cf4d1-409f-4139-88d1-1d4446c2c96c.jpeg</url>
      <title>DEV Community: Devraj Sawant</title>
      <link>https://dev.to/devrajsawant</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devrajsawant"/>
    <language>en</language>
    <item>
      <title>4. Let, Const and Var</title>
      <dc:creator>Devraj Sawant</dc:creator>
      <pubDate>Wed, 13 Aug 2025 17:37:23 +0000</pubDate>
      <link>https://dev.to/devrajsawant/4-let-const-and-var-29l6</link>
      <guid>https://dev.to/devrajsawant/4-let-const-and-var-29l6</guid>
      <description>&lt;p&gt;We all know var,const and let are used for declaring variables, but why do we have 3 keywords for the same task? Let’s find out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;VAR&lt;/u&gt;&lt;/strong&gt;:&lt;br&gt;
Before ES6 was introduced, there was only one way of declaring variable and that was 'var'&lt;br&gt;
but the problem was 'var' was function scope and not block scope&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Scope&lt;/strong&gt;&lt;br&gt;
Function scope is basically the var can be accessed anywhere in the function, no matter in which scope{} it is written&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function abc() {
  { var x = 10 }
  console.log(x); // it works even tho x was declared in scope 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this caused accidental variable leaks causing further bugs&lt;br&gt;
to resolve this Issue, &lt;strong&gt;CONST&lt;/strong&gt; and &lt;strong&gt;LET&lt;/strong&gt; was introduced in ES6&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;CONST &amp;amp; LET&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Both Const and Let was introduced in ES6&lt;br&gt;
Both were Block scope&lt;br&gt;
No redeclaration in same scope&lt;/p&gt;

&lt;p&gt;Both are similar but the only and main difference is &lt;br&gt;
Const value cannot be changed and reassigned&lt;br&gt;
however Let can be reassigned value as many time as we want&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Const are better for storing API_KEYS and other values which will stay constant&lt;/li&gt;
&lt;li&gt;Let can be used in Loops and temporary data storage
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let score = 0;
score += 10; 
console.log(score); // 10

const PI = 3.1416;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;thank You!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>3. Lexical Scope &amp; Closure</title>
      <dc:creator>Devraj Sawant</dc:creator>
      <pubDate>Tue, 12 Aug 2025 05:30:16 +0000</pubDate>
      <link>https://dev.to/devrajsawant/3-lexical-scope-closure-4j92</link>
      <guid>https://dev.to/devrajsawant/3-lexical-scope-closure-4j92</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Lexical Scope&lt;/u&gt;&lt;/strong&gt; &lt;br&gt;
Lexical Scope is a term in JS which states that &lt;br&gt;
'A function can use variable from where it is written, not where it is called'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outerFunction(){
let fruit = 'apple';
  function innerFunction(){
    console.log(fruit) 
  }

innerFunction()
}

let fruit = 'mango';
outerFunction(); 


// above function call will log 'apple' and not 'mango' 
As function used fruit variable(apple) where function was written 
and not fruit(mango) where function was called
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if the inner function can't find the variable in the outer function it  will look for global variable &lt;br&gt;
but if both are present, the variable in outer scope will be given more preference than the global variable by the inner function&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Closure&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
According to Closure - A function can still use the variable from where it is created, even if the outer code is done running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
  let x = 5;

  function inner() {
    console.log(x);
  }

  return inner;
}

const fn = outer(); // outer is finished here still whenever we call Fn we will get the value
fn(); // 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>2. Spread Operator</title>
      <dc:creator>Devraj Sawant</dc:creator>
      <pubDate>Mon, 11 Aug 2025 17:11:31 +0000</pubDate>
      <link>https://dev.to/devrajsawant/2-spread-operator-4bp1</link>
      <guid>https://dev.to/devrajsawant/2-spread-operator-4bp1</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1,2,3]
console.log(numbers) // [1,2,3]
console.log(...numbers) // 1,2,3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in above example, console logging the numbers gives the entire array but logging the same 'numbers' array with spread operators gives us the element inside an array and that is what spread operator is used for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;spread operator&lt;/strong&gt; is a special feature of Javascript which helps to expand and get the elements of any iterables such as array,string,etc.&lt;/p&gt;

&lt;p&gt;Spread simplifies multiple task such as concatenation, copying, etc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr1 = [1, 2, 3];
const copy = [...arr1]; // copy arr1 into copy -&amp;gt; [1,2,3]
const merged = [...arr1,...copy] // merge both in 1 -&amp;gt; [1,2,3,1,2,3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>snippet</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>1. Rest Parameter &amp; why do we need it</title>
      <dc:creator>Devraj Sawant</dc:creator>
      <pubDate>Sat, 09 Aug 2025 18:31:25 +0000</pubDate>
      <link>https://dev.to/devrajsawant/1-rest-parameter-why-do-we-need-it-b5l</link>
      <guid>https://dev.to/devrajsawant/1-rest-parameter-why-do-we-need-it-b5l</guid>
      <description>&lt;p&gt;quick intro - Hey, I am a frontend dev trying to level up, and to do that i have decided to daily deep dive into one concept of JS/TS and share what i have learnt so others can engage, cross question and grow.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;WHY ...REST ?&lt;/strong&gt;&lt;/u&gt;&lt;br&gt;
the problem before REST was one must know the exact number of parameters needed to be passed to the function, and if you don't know you need to use 'argument' object.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;argument object :&lt;/u&gt;&lt;br&gt;
argument object is a built-in object of JS which is available inside regular function and it holds all the argument passed to that functions, it is kind of dynamic array but it's not an array &lt;br&gt;
it has index and length , but you can't use other array methods on it such as map,filter,etc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function showArguments() {
  console.log(arguments[0]) // 10
  console.log(arguments[1]) //20
}

showArguments(10, 20); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Drawbacks :&lt;/u&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;not a real array so you can't use map,filter,etc other array methods&lt;/li&gt;
&lt;li&gt;arguments work only on normal functions not on arrow functions&lt;/li&gt;
&lt;li&gt;store parameters on basis of index and not names &lt;/li&gt;
&lt;li&gt;hard-to-read code&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;WHAT IS REST ?&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Rest is a special parameter which is used to store all/remaining parameters into real array just like 'arguments' did&lt;/p&gt;

&lt;p&gt;then why use rest?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rest is real array so you can use all the array methods with it which was not possible with arguments&lt;/li&gt;
&lt;li&gt;Rest works with arrow functions too unlike 'arguments'&lt;/li&gt;
&lt;li&gt;rest parameters can be given any naming, improving readability&lt;/li&gt;
&lt;li&gt;arguments contain only all the parameters passed but rest contains only the extras (other than explicitly defined)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;example of Rest :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(firstName, lastName, ...hobbies) {
  console.log("First Name:", firstName); // ABC
  console.log("Last Name:", lastName); // XYZ
  console.log("Hobbies:", hobbies); // ["Coding","Gaming","reading"]
}

greet("ABC", "XYZ", "Coding", "Gaming", "Reading");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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