<?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: Abhinav Deep Rastogi</title>
    <description>The latest articles on DEV Community by Abhinav Deep Rastogi (@devgrammer).</description>
    <link>https://dev.to/devgrammer</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%2F335362%2Fa7727822-0d33-4a9b-9468-ccd662784b0c.jpeg</url>
      <title>DEV Community: Abhinav Deep Rastogi</title>
      <link>https://dev.to/devgrammer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devgrammer"/>
    <language>en</language>
    <item>
      <title>JavaScript this Keyword: Why Arrow Functions Break It and How Traditional Functions Save the Day</title>
      <dc:creator>Abhinav Deep Rastogi</dc:creator>
      <pubDate>Fri, 21 Mar 2025 12:32:12 +0000</pubDate>
      <link>https://dev.to/devgrammer/javascript-this-keyword-why-arrow-functions-break-it-and-how-traditional-functions-save-the-day-2c8k</link>
      <guid>https://dev.to/devgrammer/javascript-this-keyword-why-arrow-functions-break-it-and-how-traditional-functions-save-the-day-2c8k</guid>
      <description>&lt;p&gt;Ever encountered a situation where your &lt;code&gt;this&lt;/code&gt; keyword in JavaScript doesn’t behave as expected? If you’ve used arrow functions, you might have faced this issue. Unlike traditional functions, arrow functions handle &lt;code&gt;this&lt;/code&gt; differently, and it can lead to unexpected bugs in your backend code. In this blog, we’ll explore why this happens, how to fix it, and when to use each type of function. Let’s dive in!&lt;/p&gt;




&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is the &lt;code&gt;this&lt;/code&gt; keyword in JavaScript?&lt;/li&gt;
&lt;li&gt;How Arrow Functions Handle &lt;code&gt;this&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;How Traditional Functions Handle &lt;code&gt;this&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Code Demonstration: Arrow vs Traditional Functions&lt;/li&gt;
&lt;li&gt;Common Mistakes to Avoid&lt;/li&gt;
&lt;li&gt;When to Use Arrow Functions vs Traditional Functions&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  1. What is the &lt;code&gt;this&lt;/code&gt; Keyword in JavaScript?
&lt;/h2&gt;

&lt;p&gt;In JavaScript, &lt;code&gt;this&lt;/code&gt; refers to the context in which a function is executed. It can change depending on how the function is called. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a &lt;strong&gt;method&lt;/strong&gt;, &lt;code&gt;this&lt;/code&gt; refers to the object that owns the method.&lt;/li&gt;
&lt;li&gt;In a &lt;strong&gt;global context&lt;/strong&gt;, &lt;code&gt;this&lt;/code&gt; refers to the global object (e.g., &lt;code&gt;window&lt;/code&gt; in browsers).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. How Arrow Functions Handle &lt;code&gt;this&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Arrow functions &lt;strong&gt;do not have their own &lt;code&gt;this&lt;/code&gt; binding&lt;/strong&gt;. Instead, they inherit &lt;code&gt;this&lt;/code&gt; from the parent scope (lexical scoping). This can be useful in some cases but problematic in others.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&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;obj&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;Dev&lt;/span&gt;&lt;span class="dl"&gt;"&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="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &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="c1"&gt;// `this` refers to the global object, not `obj`&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;obj&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;// Output: Hello, undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why does this happen?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Arrow functions don’t bind their own &lt;code&gt;this&lt;/code&gt;, so &lt;code&gt;this.name&lt;/code&gt; looks for &lt;code&gt;name&lt;/code&gt; in the global scope, which doesn’t exist.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. How Traditional Functions Handle &lt;code&gt;this&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Traditional functions &lt;strong&gt;have their own &lt;code&gt;this&lt;/code&gt; binding&lt;/strong&gt;, which depends on how the function is called. You can also explicitly bind &lt;code&gt;this&lt;/code&gt; using &lt;code&gt;.bind()&lt;/code&gt;, &lt;code&gt;.call()&lt;/code&gt;, or &lt;code&gt;.apply()&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&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;obj&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;Dev&lt;/span&gt;&lt;span class="dl"&gt;"&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;`Hello, &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="c1"&gt;// `this` refers to `obj`&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;obj&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;// Output: Hello, Dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why does this work?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Traditional functions bind &lt;code&gt;this&lt;/code&gt; to the object calling the method, so &lt;code&gt;this.name&lt;/code&gt; correctly refers to &lt;code&gt;obj.name&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Code Demonstration: Arrow vs Traditional Functions
&lt;/h2&gt;

&lt;p&gt;Let’s see a practical example of how &lt;code&gt;this&lt;/code&gt; behaves differently in arrow and traditional functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code:
&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;User&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="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="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Traditional Function&lt;/span&gt;
  &lt;span class="nf"&gt;greetTraditional&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;`Traditional: Hello, &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="c1"&gt;// Arrow Function&lt;/span&gt;
  &lt;span class="nx"&gt;greetArrow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Arrow: Hello, &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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&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;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Works as expected&lt;/span&gt;
&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greetTraditional&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Traditional: Hello, Alice&lt;/span&gt;

&lt;span class="c1"&gt;// Also works, but for a different reason (lexical `this`)&lt;/span&gt;
&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greetArrow&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Arrow: Hello, Alice&lt;/span&gt;

&lt;span class="c1"&gt;// Now let's break it&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;traditionalGreet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greetTraditional&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;arrowGreet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greetArrow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;traditionalGreet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Traditional: Hello, undefined (lost `this` binding)&lt;/span&gt;
&lt;span class="nf"&gt;arrowGreet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Arrow: Hello, Alice (still works due to lexical `this`)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Traditional functions lose &lt;code&gt;this&lt;/code&gt; when called without the object context.&lt;/li&gt;
&lt;li&gt;Arrow functions retain &lt;code&gt;this&lt;/code&gt; because they inherit it from the parent scope.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Common Mistakes to Avoid
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Using arrow functions for object methods where &lt;code&gt;this&lt;/code&gt; is needed.
&lt;/li&gt;
&lt;li&gt;Assuming arrow functions and traditional functions behave the same way.
&lt;/li&gt;
&lt;li&gt;Forgetting to bind &lt;code&gt;this&lt;/code&gt; in traditional functions when passing them as callbacks.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  6. When to Use Arrow Functions vs Traditional Functions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use Arrow Functions When:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need lexical &lt;code&gt;this&lt;/code&gt; (e.g., in callbacks or closures).
&lt;/li&gt;
&lt;li&gt;You want a shorter syntax for simple functions.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Use Traditional Functions When:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need dynamic &lt;code&gt;this&lt;/code&gt; binding (e.g., object methods).
&lt;/li&gt;
&lt;li&gt;You want to use &lt;code&gt;.bind()&lt;/code&gt;, &lt;code&gt;.call()&lt;/code&gt;, or &lt;code&gt;.apply()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  7. Conclusion
&lt;/h2&gt;

&lt;p&gt;Understanding how &lt;code&gt;this&lt;/code&gt; works in JavaScript is crucial for writing bug-free code. Arrow functions are great for certain use cases, but they can break your code if you rely on &lt;code&gt;this&lt;/code&gt; binding. Traditional functions, on the other hand, give you more control over &lt;code&gt;this&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt; Always think about the context in which your function will run before choosing between arrow and traditional functions.&lt;/p&gt;




&lt;h3&gt;
  
  
  Call-to-Action
&lt;/h3&gt;

&lt;p&gt;What’s your experience with &lt;code&gt;this&lt;/code&gt; in JavaScript? Have you ever been bitten by this issue? Share your thoughts in the comments below! If you found this guide helpful, don’t forget to share it with your fellow developers. 🚀&lt;/p&gt;




&lt;h3&gt;
  
  
  Additional Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this" rel="noopener noreferrer"&gt;MDN Docs on &lt;code&gt;this&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/news/when-and-why-to-use-arrow-functions-in-javascript/" rel="noopener noreferrer"&gt;JavaScript Arrow Functions vs Traditional Functions&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Your Feedback Matters! 💬
&lt;/h3&gt;

&lt;p&gt;Thank you for taking the time to read this blog! I hope you found it insightful and helpful in understanding the nuances of the &lt;code&gt;this&lt;/code&gt; keyword in JavaScript. If you have any questions, thoughts, or additional tips to share, I’d love to hear from you in the &lt;strong&gt;comments below&lt;/strong&gt;. Your feedback not only helps me improve but also enriches the discussion for fellow developers.&lt;/p&gt;

&lt;p&gt;If you enjoyed this post, please consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Liking this article&lt;/strong&gt; ❤️ to let me know it was valuable to you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sharing it&lt;/strong&gt; with your network on &lt;a href="https://twitter.com" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://linkedin.com" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, or any platform where developers hang out. Spreading knowledge is what makes our community stronger! 🌟&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Following my blog&lt;/strong&gt; for more tutorials, tips, and deep dives into programming concepts. Your support motivates me to keep creating content that matters to you.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s keep the conversation going—drop a comment, share your experiences, or suggest topics you’d like me to cover next. Together, we can learn and grow as developers! 🚀&lt;/p&gt;

&lt;p&gt;Happy coding! 😊&lt;br&gt;&lt;br&gt;
Abhinav Rastogi&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/devgrammer"&gt;@devgrammer&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://www.github.com/devgrammer" rel="noopener noreferrer"&gt;&lt;img alt="Github" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1y8wrnoazrfrbik23k95.png" width="32" height="32"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://abhinavrastogi.netlify.app/" rel="noopener noreferrer"&gt;&lt;img alt="Github" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqrubtaq7cmxh1coj1hnf.png" width="32" height="32"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Wondering Why you need to use Next Js? Read This!</title>
      <dc:creator>Abhinav Deep Rastogi</dc:creator>
      <pubDate>Sun, 28 Aug 2022 09:17:49 +0000</pubDate>
      <link>https://dev.to/devgrammer/wondering-why-you-need-to-use-next-js-read-this-5c2n</link>
      <guid>https://dev.to/devgrammer/wondering-why-you-need-to-use-next-js-read-this-5c2n</guid>
      <description>&lt;p&gt;Hey! Hope I'm talking to a passionate and smart React Dev because everything we cook in this blog's recipe has the same ingredients like hooks, states etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.datocms-assets.com%2F48401%2F1644864897-next-framework.jpeg%3Ffit%3Dmax%26w%3D900" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.datocms-assets.com%2F48401%2F1644864897-next-framework.jpeg%3Ffit%3Dmax%26w%3D900" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we both share the same development history in web development it's probably boring to work with libraries and addons packages in a fresh boilerplate like some extra seasoning, butter, or maybe a pinch of salt... No, wait it's time to switch to the fully blown framework which came with a complete ecosystem.&lt;/p&gt;

&lt;p&gt;Yes f...framework! not a library.&lt;/p&gt;

&lt;p&gt;No doubt we all are so attached to React and its rich features which help us to create magic on the browser. It's absolutely fantastic. But still, we are humans and always have a place to improve and go one level forward to optimize cons and produce more pros.&lt;/p&gt;

&lt;p&gt;So Yeah finally we have a framework to combat the drawbacks and develop systems more efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Framework v/s Library
&lt;/h2&gt;

&lt;p&gt;A Framework is a foundation upon which developers build applications while libraries provide predefined functions and classes to make their work easier. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.interviewbit.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F10%2FImage-1-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.interviewbit.com%2Fblog%2Fwp-content%2Fuploads%2F2021%2F10%2FImage-1-2.png" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Need of Next JS over React&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Speed &amp;amp; Easiness of Coding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Like as per react methodology when the new page is created it needs to be added to the router exclusively but next js brings the traditional and easier file-based routing. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--DIT1rRjH--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880%2Fhttps%3A%2F%2Fraw.githubusercontent.com%2Fakuks%2FMisc%2Fmain%2FImages%2Fnextjs_routing.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--DIT1rRjH--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880%2Fhttps%3A%2F%2Fraw.githubusercontent.com%2Fakuks%2FMisc%2Fmain%2FImages%2Fnextjs_routing.png" width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where you put your file in the folder and automatically the routes are assigned according to it. it really helps to speed up the development and also simplifies the routing flow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;br&gt;
As per comparison the static pages or web-app developed using Next js are damn fast due to server-side rendering and by default next has image optimization-like key features to provide a super fast experience, on the other side react only supports client-side rendering and provides a slow experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a buffet of many incredible features to serve you the best recipe.Here some key features are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Image Optimization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better SEO&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Internationalization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hybrid: SSG &amp;amp; SSR&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;File-system based routing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fast  Refresh &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Acceptance &amp;amp; Adoptability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next js is widely loved by web developers around the globe and also adopted by several tech giants like Netflix Jobs, TikTok, Twitch, Hulu, Notion, Nike, etc to provide a fast and immersive experience to their users and better business.&lt;/p&gt;

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

&lt;p&gt;So this blog is all about a general discussion of why we use Next over React and what are the fundamental differences between them. As you went through the blog we must agree that due to a lot of capabilities and extra powerful features Next JS wins over react in the race of performance and speed. So this blog is not an end it is just a single recipe for the whole menu. I would love to hear your feedback, comments, and suggestions to improve and provide more informative content in a simpler way please do comment below and let me know if you love to read next of Next Js. Have a great day!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Setting up your first React Project!</title>
      <dc:creator>Abhinav Deep Rastogi</dc:creator>
      <pubDate>Sun, 05 Apr 2020 14:25:12 +0000</pubDate>
      <link>https://dev.to/devgrammer/setting-up-your-first-react-project-2mll</link>
      <guid>https://dev.to/devgrammer/setting-up-your-first-react-project-2mll</guid>
      <description>&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2760%2F1%2AhrrakxVFbJDP0jKrC5D_VA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2760%2F1%2AhrrakxVFbJDP0jKrC5D_VA.png" alt="Learn React.js from Top 45 Tutorials for the past year (v.2018)" width="800" height="310"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Hang on, wait I will tell you how to set up your first react project as magic.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Basically a React Project has a lot of dependencies as its very owned requirement. So, It is necessary to integrate all the required dependencies in the project folder which can be done mostly in two ways:&lt;/span&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt; Manually (CDN or Linking files)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt; Package Managers&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;Okay Let's see the whole process in both ways&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Manually (CDN or Linking files)&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;span&gt;Basically a normal React project required three main files in the project folder in its initial state. Those three files are mentioned below:&lt;/span&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt; React.js (react.js)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt; ReactDOM.js (react-dom.js)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt; Babel.js (babel.js)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;After linking above the files the React-project is ready to work, all the JSX or React Component’s code is written under the &lt;/span&gt;&lt;em&gt;&lt;span&gt;&amp;lt;div id=” root ”&amp;gt; &amp;lt;/div&amp;gt; &lt;/span&gt;&lt;/em&gt;&lt;span&gt;tag in the body of &lt;/span&gt;&lt;strong&gt;index.html&lt;/strong&gt;&lt;span&gt;.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;span&gt; This is the way of doing projects but it is not the best and hassle-free way to set up a React project because using this way results in lack of proper directory structure as well as every component and small task you have to write a long code.&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;&lt;strong&gt;Package Manager&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;&lt;span&gt;With the help of Package manager you can set up any React project in just minutes and the process is also hassle-free.There are several package managers and bundler are available on the web. I mention some most popular and widely used package manager below:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NPM (Node Package Manager)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;It is used to take advantages of a vast ecosystem of third-party packages and easily install or update them.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;a title="npm" href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;NPM&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Webpack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Webpack is a static module bundler for modern Javascript applications. Webpack processes the application. It internally builds a dependency graph which maps every module your project needs and generates one or more bundles.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;a title="Webpack" href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yarn&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Yarn is a package manager for your code. It allows you to use and share (e.g. JavaScript) code with other developers from around the world. Yarn does this quickly, securely, and reliably so you don’t ever have to worry.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;a title="Yarn" href="https://classic.yarnpkg.com/en/" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;I selected &lt;/span&gt;&lt;strong&gt;npm&lt;/strong&gt;&lt;span&gt; as my versatile package manager which helps me to set up the react project and also help me to start a separate node server on a local machine so it is so easy to create the web app smoothly and also provide features like build-run, start the server and terminate the server.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;For installing npm and node.js on your respected machine you can take reference of blog link mentioned below:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://phoenixnap.com/kb/install-node-js-npm-on-windows" rel="noopener noreferrer"&gt;&lt;strong&gt;Guide to install npm and node.js on machine.&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;About NPM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;npm is the world’s largest software registry. Open-source developers from every continent use npm to share and borrow packages and many organizations use npm to manage private development as well.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;After installation as windows, users use there Powershell and mac/Linux user can access npm via terminal as npm CLI.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Some basic command you can use with npm are:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For checking version&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Command: &lt;/span&gt;&lt;span&gt;npm -v&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For upgrading npm globally&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Command:&lt;/span&gt;&lt;span&gt; npm install npm@lastest -g&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For installing any Module/Packages via npm&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Command:&lt;/span&gt;&lt;span&gt; npm install &amp;lt;packageName&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;After installing package through npm results to the generation of two files:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;It contains all the necessary file or module information required for the project.&lt;/span&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;package.lock.json&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;It consists of a version (a specific version of dependencies).&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For starting the packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Command:&lt;/span&gt;&lt;span&gt; npm start&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;As I started documenting my journey of React JS which always encourages me to provide the best and easiest learning resource to the beginner so they can do stuff in a smooth and efficient way. as I write my very first dev.to post of the Series "An adventurous journey of React JS" and I observed quite good response and I'm really thankful for all the readers who find my post helpful and also welcome suggestion to improve if any?. I hope you like this second chapter of the Series. Please provide your great suggestion in the comment section and share in your circle if you find it helpful.&lt;/span&gt;&lt;/p&gt;

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

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

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

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

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

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

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

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

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

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

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

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

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

</description>
      <category>react</category>
      <category>npm</category>
      <category>node</category>
      <category>webpack</category>
    </item>
    <item>
      <title>What is ReactJS?</title>
      <dc:creator>Abhinav Deep Rastogi</dc:creator>
      <pubDate>Wed, 04 Mar 2020 03:26:53 +0000</pubDate>
      <link>https://dev.to/devgrammer/react-js-14i1</link>
      <guid>https://dev.to/devgrammer/react-js-14i1</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcuratti.com%2Fwp-content%2Fuploads%2F2017%2F11%2FReactJS-1000x500.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcuratti.com%2Fwp-content%2Fuploads%2F2017%2F11%2FReactJS-1000x500.jpg" alt="ReactJS" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;b&gt;What is  React JS?&lt;/b&gt;&lt;br&gt;
ReactJS is a Javascript library for building frontend web application or UI.&lt;br&gt;
ReactJS allows us to create reusable UI components. It is developed by Facebook.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Features of React&lt;/b&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reusable Components&lt;/li&gt;
&lt;li&gt;Open Source&lt;/li&gt;
&lt;li&gt;Efficient and fast&lt;/li&gt;
&lt;li&gt;Work in Browser&lt;/li&gt;
&lt;li&gt;Large Community&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;b&gt;Basic part of React library&lt;/b&gt;&lt;br&gt;
a. Components&lt;br&gt;
b. Props.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Components&lt;/b&gt;&lt;br&gt;
Components are the building blocks of any React app. Basically any class or function in React is considered as &lt;b&gt;component&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Props&lt;/b&gt;&lt;br&gt;
&lt;b&gt;“Props”&lt;/b&gt; is a special keyword in React, which stands for properties and is being used for passing data from one component to another.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; How React Works?&lt;/b&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcontent.altexsoft.com%2Fmedia%2F2017%2F05%2FReal-vs-Virtual-DOM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcontent.altexsoft.com%2Fmedia%2F2017%2F05%2FReal-vs-Virtual-DOM.png" alt="Working Demostration of React" width="800" height="232"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
React make the changes and it is done by creating a Virtual DOM by comparing the virtual DOMs with existing loaded DOMs.&lt;br&gt;
React find the changes and render the exact code which is changed instead of rendering the whole page or whole code.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; Pros &amp;amp; Cons of React &lt;/b&gt;&lt;br&gt;
&lt;b&gt;Pros:&lt;/b&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Virtual DOM makes the User experience better and the developer’s work faster.&lt;/li&gt;
&lt;li&gt;Permission to reuse React components significantly saves time.&lt;/li&gt;
&lt;li&gt;One-direction data flow in ReactJS provides a stable code.&lt;/li&gt;
&lt;li&gt;An Opensource Facebook library: constantly developing &amp;amp; open to the community.&lt;/li&gt;
&lt;li&gt;Redux: convenient state container.&lt;/li&gt;
&lt;li&gt;Wide React and Redux toolset&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;b&gt;Cons:&lt;/b&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The high pace of development.&lt;/li&gt;
&lt;li&gt;Poor documentation.&lt;/li&gt;
&lt;li&gt;‘HTML in my JavaScript!’ – JSX as a barrier.&lt;/li&gt;
&lt;li&gt;Additional SEO hassle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As a ReactJs learner and developer, I quite observed a problem is lack of good documentation which leads to some big problems for beginners. So I decided to share my journey on React with my community so I can provide a better explanation of react stuff in a quite simple and easy way and yeah also not bulky in words and paragraphs or I say in minimum words. This is my first post on Dev.to I hope you like it. If you like my post please show your support and give your opinion on comments and tell me if you want more ahead on ReactJs.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
