<?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: Tushar</title>
    <description>The latest articles on DEV Community by Tushar (@tushar_pal).</description>
    <link>https://dev.to/tushar_pal</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%2F1680938%2F6e0a5d90-37d1-4a27-b356-9b2eb9fe4229.jpeg</url>
      <title>DEV Community: Tushar</title>
      <link>https://dev.to/tushar_pal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tushar_pal"/>
    <language>en</language>
    <item>
      <title>REDUX in short, but Deep!!!</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Mon, 14 Oct 2024 09:47:46 +0000</pubDate>
      <link>https://dev.to/tushar_pal/redux-in-short-but-deep-43k6</link>
      <guid>https://dev.to/tushar_pal/redux-in-short-but-deep-43k6</guid>
      <description>&lt;p&gt;Redux is a state management library for JavaScript applications, mostly used with React. It helps manage application state in a predictable way by using a single store, actions, reducers, and middleware. Learning Redux will enable you to handle complex state logic and side effect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reducer&lt;/strong&gt;&lt;br&gt;
Reducers are pure functions that manage state transitions in applications using Redux or the useReducer hook. They take the current state and an action as arguments and return a new state. Reducers help manage complex state logic in a predictable way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slice&lt;/strong&gt;&lt;br&gt;
In Redux Toolkit, a slice is a collection of reducer logic and actions for a specific feature of your application. Slices simplify Redux code by bundling related logic together and generating actions and action creators automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Action&lt;/strong&gt;&lt;br&gt;
Actions in Redux are plain JavaScript objects that represent an intention to change the state. They contain a type field indicating the type of action and any additional payload data. Actions are dispatched to reducers to update the application state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To read data:&lt;/strong&gt; &lt;br&gt;
we use SELECTOR to SUBSCRIBE to the store&lt;/p&gt;

&lt;p&gt;when we click ADD button , it dispatches an ACTION which calls REDUCER function which updates SLICE of our REUDX store and when this data is updated then the COMPONENT which is using this data by SUBSCRIBING to store also changes and latest data is shown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fce9lbefyll6mgzyz2a17.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fce9lbefyll6mgzyz2a17.png" alt="Image description" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>redux</category>
      <category>basic</category>
    </item>
    <item>
      <title>ReactDOM vs React : why are they in seprate files ?</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Mon, 12 Aug 2024 18:45:46 +0000</pubDate>
      <link>https://dev.to/tushar_pal/reactdom-vs-react-why-are-they-in-seprate-files--fam</link>
      <guid>https://dev.to/tushar_pal/reactdom-vs-react-why-are-they-in-seprate-files--fam</guid>
      <description>&lt;h3&gt;
  
  
  Why React and ReactDOM Are Separate: An Easy Explanation
&lt;/h3&gt;

&lt;p&gt;If you're getting started with React, you might wonder why there are two separate packages: &lt;strong&gt;React&lt;/strong&gt; and &lt;strong&gt;ReactDOM&lt;/strong&gt;. Why not combine them into one? Let’s break it down.&lt;/p&gt;

&lt;h4&gt;
  
  
  What’s React?
&lt;/h4&gt;

&lt;p&gt;React is a library that helps you build user interfaces (UIs). Think of it as a tool to create different parts of a website, like buttons, menus, and forms, in a way that’s easy to manage and update. It’s not just for websites; it can also be used for mobile apps and other platforms.&lt;/p&gt;

&lt;h4&gt;
  
  
  What’s ReactDOM?
&lt;/h4&gt;

&lt;p&gt;ReactDOM is like a translator that helps React work specifically with web browsers. It takes the components you build with React and turns them into something the browser can understand and display on your screen.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Keep Them Separate?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flexibility Across Platforms&lt;/strong&gt;: React can be used for more than just websites. By keeping React separate from ReactDOM, it can also work with mobile apps (through &lt;strong&gt;React Native&lt;/strong&gt;) and other platforms. This separation makes React more flexible and powerful.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Focused Functionality&lt;/strong&gt;: By having two separate packages, each can focus on doing its job really well. React handles the creation of components, while ReactDOM focuses on displaying them in the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Smaller Size&lt;/strong&gt;: Not every project needs all the features of ReactDOM. For example, if you’re building a mobile app, you don’t need ReactDOM at all. This separation helps keep your projects lean and efficient.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Special Features for the Web&lt;/strong&gt;: ReactDOM provides special features and methods specifically for web development, like rendering components to the page and managing events.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  How ReactDOM Works
&lt;/h4&gt;

&lt;p&gt;Imagine you build a button component with React. ReactDOM is the tool that takes that button and places it on the web page. When something changes (like the button’s text or color), ReactDOM updates the page without reloading everything. This makes your website faster and smoother.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Big Picture
&lt;/h4&gt;

&lt;p&gt;The separation of React and ReactDOM is a smart design choice. It allows React to be used in different environments (web, mobile, etc.), keeps your projects small and efficient, and ensures that each library can be updated and improved independently.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Understanding why React and ReactDOM are separate helps you see the bigger picture of how React works. It’s all about flexibility, efficiency, and focused functionality. Whether you’re building a website or a mobile app, this separation makes it easier to create amazing user interfaces.&lt;/p&gt;

</description>
      <category>basic</category>
      <category>2minread</category>
      <category>mustknow</category>
    </item>
    <item>
      <title>Class Based Components DEEP DIVE</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sun, 04 Aug 2024 15:40:50 +0000</pubDate>
      <link>https://dev.to/tushar_pal/class-based-components-deep-dive-5fb0</link>
      <guid>https://dev.to/tushar_pal/class-based-components-deep-dive-5fb0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction to Class-Based Components in React
&lt;/h2&gt;

&lt;p&gt;In this Blog we will cover what is &lt;code&gt;ClASS&lt;/code&gt; BASED components and how to pass &lt;code&gt;PROP&lt;/code&gt; in class based component&lt;/p&gt;

&lt;p&gt;Class-based components are a foundational concept in React. Although the trend has shifted towards functional components with hooks, understanding class-based components is essential for working with existing codebases and grasping React's core concepts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax of Class-Based Components
&lt;/h3&gt;

&lt;p&gt;Class-based components in React are defined using ES6 classes that extend the &lt;code&gt;React.Component&lt;/code&gt; class. Here’s a basic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserClass&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;UserClass&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Extends&lt;/strong&gt;: The &lt;code&gt;extends Component&lt;/code&gt; syntax informs React that &lt;code&gt;UserClass&lt;/code&gt; is a class-based component.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Render Method&lt;/strong&gt;: The &lt;code&gt;render&lt;/code&gt; method returns the JSX that will be displayed on the screen.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;userClass&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To summarize, we create a JavaScript class &lt;code&gt;UserClass&lt;/code&gt; which extends from &lt;code&gt;React.Component&lt;/code&gt; that comes from the React library.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to pass props inside CLASS based Component
&lt;/h3&gt;

&lt;p&gt;Props are used to pass data from parent components to child components. Here's how to work with props in class-based components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sending Props:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserClass&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"John Doe"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Receiving Props:&lt;/strong&gt;&lt;br&gt;
We will create a constructor and this constructor will recieve the &lt;code&gt;PROP&lt;/code&gt;and will use &lt;code&gt;SUPER&lt;/code&gt; keryword to recieve and we always have to write it otherwise it will throw error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserClass&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&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;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&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="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Constructor&lt;/strong&gt;: Initializes the component and receives props.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Super&lt;/strong&gt;: Passes the props to the base &lt;code&gt;Component&lt;/code&gt; class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;this.props&lt;/strong&gt;: Accesses the props within the component.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The console will show the value of the prop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function Components Comparison
&lt;/h3&gt;

&lt;p&gt;For comparison, here’s how the same task is done using functional components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;To use the prop within a class-based component, you would write &lt;code&gt;this.props.name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The method of sending props is the same for both class-based and functional components. The primary difference lies in how props are received and used: class-based components use the constructor and the &lt;code&gt;super&lt;/code&gt; keyword.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>react</category>
      <category>deepdive</category>
      <category>basic</category>
    </item>
    <item>
      <title>Understanding JS and its Single Threaded nature</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sat, 27 Jul 2024 15:31:07 +0000</pubDate>
      <link>https://dev.to/tushar_pal/understanding-js-and-its-single-threaded-nature-13j</link>
      <guid>https://dev.to/tushar_pal/understanding-js-and-its-single-threaded-nature-13j</guid>
      <description>&lt;h2&gt;
  
  
  Understanding JavaScript
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Browser Compatibility
&lt;/h3&gt;

&lt;p&gt;JavaScript (JS) is a fundamental component of web development, forming the third pillar alongside HTML and CSS. Browsers inherently understand these three languages, standardizing the development process across different platforms and devices. This widespread compatibility makes JavaScript indispensable for creating dynamic, interactive web pages that engage users.&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript Beyond the Browser
&lt;/h3&gt;

&lt;p&gt;The advent of Node.js has significantly expanded the use of JavaScript. Initially confined to client-side scripting, Node.js allows JavaScript to be utilized on the server side as well. This means that developers can now use a single language for both front-end and back-end development, streamlining the development process and enabling the creation of full-stack JavaScript applications. This synergy between front-end and back-end makes JavaScript an incredibly powerful tool in a developer's toolkit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Comparison with Other Languages
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Static vs Dynamic Typing
&lt;/h4&gt;

&lt;p&gt;Transitioning from JavaScript's versatility in both front-end and back-end development, let's delve into how it compares with other languages like C++ and C. These languages are statically typed, meaning variable types are determined at compile-time. This leads to stricter type enforcement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: You cannot store a string like "hello" in an integer variable in C++ or C.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This strict type system has its advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Benefits&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Early detection of type-related errors during compile-time.&lt;/li&gt;
&lt;li&gt;Potentially optimized performance due to known variable types.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;In contrast, JavaScript is dynamically typed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This flexibility allows developers to move quickly without worrying about strict type constraints, which can accelerate development, especially during prototyping or when building less complex applications. It’s like having the freedom to change gears on a bike mid-ride without having to stop and adjust anything manually.&lt;/p&gt;

&lt;h3&gt;
  
  
  Single-Threaded Nature of JavaScript
&lt;/h3&gt;

&lt;p&gt;Moving from typing systems to execution models, another key aspect of JavaScript is its single-threaded nature. JavaScript operates on a single-threaded model, meaning it can only execute one task at a time within a single thread. This might seem limiting, especially when considering modern multi-core processors, such as an &lt;em&gt;8-core MacBook Air&lt;/em&gt;. &lt;br&gt;
Each core can handle a separate task, which raises the question: does single-threaded JavaScript mean only one task at a time, regardless of the available cores?&lt;/p&gt;
&lt;h4&gt;
  
  
  Context Switching and Concurrency
&lt;/h4&gt;

&lt;p&gt;Despite being single-threaded, JavaScript can manage multiple tasks through asynchronous programming. This is where context switching comes into play. The JavaScript runtime, particularly within environments like Node.js, can handle multiple tasks by switching contexts between different operations, allowing for a form of concurrency even within a single thread. This enables efficient handling of I/O operations, such as network requests or file system operations, without blocking the main execution thread.&lt;/p&gt;

&lt;p&gt;To observe how many cores are in use while running JavaScript code, you can use system monitoring tools like &lt;code&gt;htop&lt;/code&gt; in the terminal. This command provides a real-time view of the system's resource usage, including CPU cores, memory, and processes, which can help in understanding the distribution and performance of your JavaScript applications:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;htop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;JavaScript's evolution from a purely front-end language to a versatile full-stack tool has transformed web development. Its dynamic typing allows for rapid development, and despite its single-threaded nature, it efficiently manages concurrency through context switching. Understanding these fundamental aspects of JavaScript equips developers to better leverage its strengths and address its limitations in various development scenarios. By appreciating these nuances, developers can make more informed decisions, crafting solutions that are both effective and efficient.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>basic</category>
      <category>learning</category>
      <category>deepdive</category>
    </item>
    <item>
      <title>How language works inside the computer</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sat, 27 Jul 2024 15:08:45 +0000</pubDate>
      <link>https://dev.to/tushar_pal/how-language-works-inside-the-computer-55l4</link>
      <guid>https://dev.to/tushar_pal/how-language-works-inside-the-computer-55l4</guid>
      <description>&lt;h3&gt;
  
  
  Understanding How Your Computer Runs Applications: A Simple Guide
&lt;/h3&gt;

&lt;p&gt;Have you ever wondered how your computer runs your favorite apps and stores all those memorable photos? Let's break it down in a simple and relatable way.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Basics: RAM and SSD
&lt;/h4&gt;

&lt;p&gt;First, it's important to understand two key components of your computer: RAM (Random Access Memory) and SSD (Solid State Drive).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSD&lt;/strong&gt;: Think of your SSD as a huge, fast library where all your apps, photos, and files are stored. It’s where everything lives when your computer is off.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RAM&lt;/strong&gt;: Now, imagine RAM as your work desk. When you want to use an app or look at a photo, you take it out of the library (SSD) and place it on your desk (RAM). RAM is much faster than SSD, so it helps your computer run applications quickly and smoothly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you open an app, it moves from the SSD to the RAM, where it can be quickly accessed and used.&lt;/p&gt;

&lt;h4&gt;
  
  
  How Apps Run: Compiled vs. Interpreted Languages
&lt;/h4&gt;

&lt;p&gt;Now that you know how your computer manages storage and memory, let's dive into how it runs the apps you love. The instructions written by developers need to be understood by your computer, which happens through a process called compiling or interpreting, depending on the programming language used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compiled Languages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Compiled languages, like C++ and Java, work like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write the Code&lt;/strong&gt;: Developers write the app in a human-readable language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compile&lt;/strong&gt;: A compiler translates this code into machine language (binary code: 0s and 1s) that your computer can understand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run&lt;/strong&gt;: You can now run the app.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If there's an error in the code, the compiler won’t complete the translation, and you won’t be able to run the app until the error is fixed.&lt;/p&gt;

&lt;p&gt;Here's a simple example in C++:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Hello, world!"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code needs to be compiled before it can run. If there’s an error, it won’t compile, and you’ll need to fix the error first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interpreted Languages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Interpreted languages, like JavaScript and Python, are a bit different:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write the Code&lt;/strong&gt;: Developers write the app in a human-readable language.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run&lt;/strong&gt;: An interpreter translates the code line by line as it runs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The advantage here is that even if there's an error later in the code, the parts before the error can still run. This allows for more flexibility during development.&lt;/p&gt;

&lt;p&gt;Here's a simple example in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, world!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code runs directly without needing to be compiled first.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Does This Matter?
&lt;/h4&gt;

&lt;p&gt;Understanding the difference between compiled and interpreted languages helps you appreciate how different apps are built and run. It also highlights the importance of error handling and debugging in software development.&lt;/p&gt;

&lt;p&gt;So, the next time you open an app or browse through your photos, you'll have a better understanding of the complex processes happening behind the scenes, all thanks to RAM, SSD, and the way code is executed!&lt;/p&gt;

</description>
      <category>basic</category>
      <category>language</category>
    </item>
    <item>
      <title>Upcoming</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sat, 20 Jul 2024 17:03:00 +0000</pubDate>
      <link>https://dev.to/tushar_pal/upcoming-1f23</link>
      <guid>https://dev.to/tushar_pal/upcoming-1f23</guid>
      <description>&lt;p&gt;Nothing to post this week!! gonna post some backend blogs soon.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Dependencies in Node.js Projects</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sat, 13 Jul 2024 17:27:48 +0000</pubDate>
      <link>https://dev.to/tushar_pal/understanding-dependencies-in-nodejs-projects-44i3</link>
      <guid>https://dev.to/tushar_pal/understanding-dependencies-in-nodejs-projects-44i3</guid>
      <description>&lt;h1&gt;
  
  
  Understanding Dependencies in Node.js Projects
&lt;/h1&gt;

&lt;p&gt;When working on a Node.js project, managing dependencies is a crucial aspect that ensures your project runs smoothly. Dependencies are the libraries or packages your project needs to function. There are two main types of dependencies you should be aware of: devDependencies and normal dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Dependencies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  DevDependencies
&lt;/h3&gt;

&lt;p&gt;These are the packages required only during the development phase. They are not needed in the production environment. For example, tools like parcel, webpack, or babel, which help in building or bundling your project, are usually listed as devDependencies.&lt;/p&gt;

&lt;p&gt;Here's an example of how to define a devDependency in your &lt;code&gt;package.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"devDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"parcel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^2.8.3"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Normal Dependencies
&lt;/h3&gt;

&lt;p&gt;These are the packages that your project needs in both development and production environments. Examples include frameworks like React, libraries for making HTTP requests, or any other code that your application relies on to run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Versioning Symbols
&lt;/h2&gt;

&lt;p&gt;In the &lt;code&gt;package.json&lt;/code&gt; file, you might notice symbols like &lt;code&gt;^&lt;/code&gt; or &lt;code&gt;~&lt;/code&gt; before the version numbers. These symbols are used to specify version ranges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Caret (&lt;code&gt;^&lt;/code&gt;)&lt;/strong&gt;: This symbol allows updates to minor versions. For example, &lt;code&gt;"parcel": "^2.8.3"&lt;/code&gt; means any version from &lt;code&gt;2.8.3&lt;/code&gt; to less than &lt;code&gt;3.0.0&lt;/code&gt; is acceptable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tilde (&lt;code&gt;~&lt;/code&gt;)&lt;/strong&gt;: This symbol allows updates to patch versions. For example, &lt;code&gt;"parcel": "~2.8.3"&lt;/code&gt; means any version from &lt;code&gt;2.8.3&lt;/code&gt; to less than &lt;code&gt;2.9.0&lt;/code&gt; is acceptable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  package.json and package-lock.json
&lt;/h2&gt;

&lt;p&gt;Both &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;package-lock.json&lt;/code&gt; are essential for managing dependencies in a Node.js project, but they serve different purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;package.json&lt;/strong&gt;: This file lists the dependencies your project needs and can include version ranges (&lt;code&gt;^&lt;/code&gt; or &lt;code&gt;~&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;package-lock.json&lt;/strong&gt;: This file locks down the exact versions of each dependency, ensuring that every time you or someone else installs the project, the same versions are used.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Understanding the Configuration and Node Modules
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;package.json&lt;/code&gt; file can be seen as part of your project's configuration, specifying which packages are needed and their respective versions. The &lt;code&gt;node_modules&lt;/code&gt; folder is like a database where all these packages are installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transitive Dependencies
&lt;/h2&gt;

&lt;p&gt;Dependencies can have their own dependencies, creating a chain known as transitive dependencies. For example, Parcel might depend on other packages, and those packages might depend on even more packages. This chain is automatically managed for you, ensuring that all necessary packages are installed.&lt;/p&gt;




&lt;p&gt;I hope this gives you a clearer understanding of how dependencies work in Node.js projects. Managing these correctly ensures your project runs efficiently and as expected, both during development and in production.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>basic</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why we use LINK tag instead of &lt;a&gt; in REACTJS</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Fri, 05 Jul 2024 16:03:33 +0000</pubDate>
      <link>https://dev.to/tushar_pal/why-we-use-link-tag-instead-of-in-reactjs-8h3</link>
      <guid>https://dev.to/tushar_pal/why-we-use-link-tag-instead-of-in-reactjs-8h3</guid>
      <description>&lt;h2&gt;
  
  
  Why We Use the &lt;code&gt;Link&lt;/code&gt; Tag of &lt;code&gt;react-router-dom&lt;/code&gt; Instead of the &lt;code&gt;a&lt;/code&gt; Tag in JSX Files
&lt;/h2&gt;

&lt;p&gt;When building a ReactJS application, navigating between pages is a crucial aspect of the user experience. However, the way we navigate between pages can have a significant impact on the performance and user experience of our application. In this article, we'll explore why we should use the &lt;code&gt;Link&lt;/code&gt; component from &lt;code&gt;react-router-dom&lt;/code&gt; instead of the plain HTML &lt;code&gt;a&lt;/code&gt; tag in our JSX files.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem with the &lt;code&gt;a&lt;/code&gt; Tag
&lt;/h3&gt;

&lt;p&gt;When we use a plain HTML &lt;code&gt;a&lt;/code&gt; tag to navigate between pages, the browser performs a full page reload. This means that the browser sends a request to the server, which responds with a new HTML page. This process involves a full page reload, which can be slower and less efficient than client-side routing.&lt;/p&gt;

&lt;p&gt;Here is an example of using the &lt;code&gt;a&lt;/code&gt; tag in a React component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Home Page&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Go to About Page&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, clicking the "Go to About Page" link will cause a full page reload as the browser requests the &lt;code&gt;/about&lt;/code&gt; page from the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Advantages of &lt;code&gt;react-router-dom&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;On the other hand, when we use the &lt;code&gt;Link&lt;/code&gt; component from &lt;code&gt;react-router-dom&lt;/code&gt;, it doesn't trigger a full page reload. Instead, it uses JavaScript to update the URL in the browser's address bar and render the new page content without requesting a new HTML page from the server.&lt;/p&gt;

&lt;p&gt;But remember Link tag is just a wrap up over &amp;lt; a &amp;gt; you can see this in chrome developer tools&lt;/p&gt;

&lt;p&gt;Here are some advantages of using &lt;code&gt;react-router-dom&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client-side routing&lt;/strong&gt;: &lt;code&gt;react-router-dom&lt;/code&gt; handles routing entirely on the client-side, which means that the browser updates the URL without requesting a new page from the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JavaScript-based navigation&lt;/strong&gt;: &lt;code&gt;react-router-dom&lt;/code&gt; uses JavaScript to navigate between pages, which allows for a faster and more efficient navigation experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No server request&lt;/strong&gt;: Because &lt;code&gt;react-router-dom&lt;/code&gt; handles routing on the client-side, it doesn't send a request to the server when you navigate between pages, which means that the page doesn't reload.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Disadvantages of Full Page Reloads
&lt;/h3&gt;

&lt;p&gt;Full page reloads can have several disadvantages, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Loss of State&lt;/strong&gt;: When the page reloads, the entire application state is lost, which means that any unsaved data, user input, or temporary state is discarded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Poor User Experience&lt;/strong&gt;: Page reloads can be jarring and disrupt the user's flow, leading to a poor user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Slower Performance&lt;/strong&gt;: Page reloads can be slower than client-side routing, which can negatively impact the application's performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Using the &lt;code&gt;Link&lt;/code&gt; Tag from &lt;code&gt;react-router-dom&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;First, ensure you have &lt;code&gt;react-router-dom&lt;/code&gt; installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, you can use the &lt;code&gt;Link&lt;/code&gt; component like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Home Page&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Go to About Page&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;function&lt;/span&gt; &lt;span class="nf"&gt;About&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;About Page&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Go to Home Page&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;exact&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;About&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;Router&lt;/code&gt; component wraps the entire application to enable routing.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Link&lt;/code&gt; component is used for navigation instead of the &lt;code&gt;a&lt;/code&gt; tag.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Switch&lt;/code&gt; component ensures that only one route is rendered at a time.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Route&lt;/code&gt; components define the paths and corresponding components to render.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Using the &lt;code&gt;Link&lt;/code&gt; component from &lt;code&gt;react-router-dom&lt;/code&gt; instead of the plain HTML &lt;code&gt;a&lt;/code&gt; tag in your JSX files is essential for creating a smooth and efficient navigation experience in your ReactJS application. By leveraging client-side routing, you can avoid full page reloads, maintain application state, and provide a better overall user experience.&lt;/p&gt;




</description>
      <category>javascript</category>
      <category>react</category>
      <category>basic</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Parcel the real hero of REACT</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Mon, 01 Jul 2024 08:43:04 +0000</pubDate>
      <link>https://dev.to/tushar_pal/parcel-the-real-hero-of-react-3gai</link>
      <guid>https://dev.to/tushar_pal/parcel-the-real-hero-of-react-3gai</guid>
      <description>&lt;h2&gt;
  
  
  Elevating React Development with Parcel
&lt;/h2&gt;

&lt;p&gt;In the dynamic world of web development, tools that enhance productivity and streamline workflows are invaluable. Enter &lt;strong&gt;Parcel&lt;/strong&gt;, a bundler that not only simplifies but also supercharges the development of React applications, complementing React's capabilities with essential features.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Parcel's Role
&lt;/h3&gt;

&lt;p&gt;While React excels in creating interactive user interfaces, Parcel steps in to handle the complexities of bundling and optimizing these applications. Unlike React, which focuses on rendering components and managing state, Parcel enhances the development process by automating tasks that would otherwise be time-consuming and tedious.&lt;/p&gt;

&lt;h3&gt;
  
  
  Seamless Integration with React
&lt;/h3&gt;

&lt;p&gt;Integrating Parcel with React is seamless. By simply invoking Parcel from the command line, developers can initiate a powerful development environment for their React projects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx parcel index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Parcel's Superpowers for React Developers
&lt;/h3&gt;

&lt;p&gt;Here’s how Parcel enhances React development:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Rapid Development Setup
&lt;/h3&gt;

&lt;p&gt;Parcel swiftly sets up a local development server (&lt;code&gt;localhost:1234&lt;/code&gt;) and enables Hot Module Replacement (HMR). This means developers can see changes instantly reflected in the browser without manually refreshing the page. This quick feedback loop significantly speeds up development cycles.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Production-Ready Optimizations
&lt;/h3&gt;

&lt;p&gt;When it's time to deploy the React application, Parcel optimizes the build for production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Image Optimization&lt;/strong&gt;: Automatically compresses and optimizes images, improving load times.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minification&lt;/strong&gt;: Reduces the size of JavaScript, CSS, and HTML files by removing unnecessary characters and whitespace.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Differential Bundling&lt;/strong&gt;: Ensures compatibility with older browsers by splitting bundles into smaller files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Enhanced Error Handling
&lt;/h3&gt;

&lt;p&gt;Parcel improves the debugging experience with clear, on-screen error messages. This user-friendly approach helps developers quickly identify and resolve issues, minimizing downtime.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Efficient Code Management
&lt;/h3&gt;

&lt;p&gt;Using tree shaking, Parcel eliminates unused code from production bundles, ensuring that only necessary code is included. This optimization results in faster load times and improved performance for React applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Choose Parcel for React?
&lt;/h3&gt;

&lt;p&gt;Parcel's integration with React empowers developers by handling complex build configurations behind the scenes. This allows React developers to focus more on writing code and less on configuring build tools. The combination of React's declarative components with Parcel's robust bundling capabilities creates a synergy that enhances productivity and code quality.&lt;/p&gt;

&lt;h3&gt;
  
  
  Embracing the Future of Web Development
&lt;/h3&gt;

&lt;p&gt;In conclusion, Parcel isn't just a bundler; it's a catalyst for elevating React development. By seamlessly integrating with React and providing essential tools for development and optimization, Parcel empowers developers to create exceptional web applications efficiently.&lt;/p&gt;

&lt;p&gt;Whether you're starting a new React project or optimizing an existing one, Parcel offers the tools and workflow enhancements that modern web development demands. Embrace Parcel as your bundler of choice and experience a new level of productivity and efficiency in building React applications.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>Understanding 'getElementById' in depth</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sat, 29 Jun 2024 16:48:29 +0000</pubDate>
      <link>https://dev.to/tushar_pal/understanding-getelementbyid-in-depth-1886</link>
      <guid>https://dev.to/tushar_pal/understanding-getelementbyid-in-depth-1886</guid>
      <description>&lt;p&gt;The &lt;code&gt;getElementById&lt;/code&gt; method is a fundamental JavaScript function used to select a single HTML element by its id attribute. It returns the element object representing the element whose id property matches the specified string.&lt;/p&gt;

&lt;h3&gt;
  
  
  Detailed Explanation:
&lt;/h3&gt;

&lt;h3&gt;
  
  
  What is &lt;code&gt;getElementById&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;getElementById&lt;/code&gt; method is a part of the Document Object Model (DOM) API, which provides a way to programmatically interact with HTML and XML documents. This method is used to retrieve an element from the DOM by its unique &lt;code&gt;id&lt;/code&gt; attribute.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;id&lt;/code&gt;: The &lt;code&gt;id&lt;/code&gt; parameter is a string representing the unique id attribute of the HTML element you want to retrieve.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example Usage:
&lt;/h3&gt;

&lt;p&gt;Let's say you have the following HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;htmlCopy code
&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In your &lt;code&gt;script.js&lt;/code&gt; file, you can use &lt;code&gt;getElementById&lt;/code&gt; to select the &lt;code&gt;div&lt;/code&gt; and manipulate it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;jsxCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Selecting the Element&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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


&lt;p&gt;This line of code retrieves the &lt;code&gt;div&lt;/code&gt; element with the id &lt;code&gt;root&lt;/code&gt;. The &lt;code&gt;getElementById&lt;/code&gt; method returns a reference to this element, allowing you to manipulate it programmatically.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Creating and Appending a Child Element&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;javascriptCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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


&lt;p&gt;Here, we first create an &lt;code&gt;h1&lt;/code&gt; element and set its inner HTML to "Hello World". We then append this &lt;code&gt;h1&lt;/code&gt; element as a child to the &lt;code&gt;root&lt;/code&gt; element using the &lt;code&gt;appendChild&lt;/code&gt; method.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Benefits of Using &lt;code&gt;getElementById&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Since IDs are unique within a document, &lt;code&gt;getElementById&lt;/code&gt; is very fast and efficient.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity&lt;/strong&gt;: It's a straightforward way to access a specific element without needing to traverse the DOM tree.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Readability&lt;/strong&gt;: Code that uses &lt;code&gt;getElementById&lt;/code&gt; is generally easier to read and understand because it clearly indicates which element is being selected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Common Use Cases
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Manipulating Content&lt;/strong&gt;: Changing the text or HTML content of an element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Styling&lt;/strong&gt;: Applying styles or classes to an element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Handling&lt;/strong&gt;: Adding event listeners to an element to handle user interactions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example: Changing Content and Adding an Event Listener
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;htmlCopy code
&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Original Content&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"changeContentButton"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Change Content&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;changeContentButton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&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;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content Changed!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We select the &lt;code&gt;div&lt;/code&gt; with the id &lt;code&gt;root&lt;/code&gt; and the &lt;code&gt;button&lt;/code&gt; with the id &lt;code&gt;changeContentButton&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We add a click event listener to the button that changes the content of the &lt;code&gt;root&lt;/code&gt; element when the button is clicked.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Understanding getElementById</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sat, 29 Jun 2024 16:45:08 +0000</pubDate>
      <link>https://dev.to/tushar_pal/understanding-getelementbyid-4ao7</link>
      <guid>https://dev.to/tushar_pal/understanding-getelementbyid-4ao7</guid>
      <description>&lt;p&gt;The &lt;code&gt;getElementById&lt;/code&gt; method is a fundamental JavaScript function used to select a single HTML element by its id attribute. It returns the element object representing the element whose id property matches the specified string.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example Usage:
&lt;/h3&gt;

&lt;p&gt;Let's say you have the following HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In your &lt;code&gt;script.js&lt;/code&gt; file, you can use &lt;code&gt;getElementById&lt;/code&gt; to select the &lt;code&gt;div&lt;/code&gt; and manipulate it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;When you open your HTML file in a browser, the &lt;code&gt;div&lt;/code&gt; with the id &lt;code&gt;root&lt;/code&gt; will now contain an &lt;code&gt;h1&lt;/code&gt; element with the text "Hello World".&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating and Appending a Heading in JavaScript</title>
      <dc:creator>Tushar</dc:creator>
      <pubDate>Sat, 29 Jun 2024 16:43:49 +0000</pubDate>
      <link>https://dev.to/tushar_pal/creating-and-appending-a-heading-in-javascript-31jl</link>
      <guid>https://dev.to/tushar_pal/creating-and-appending-a-heading-in-javascript-31jl</guid>
      <description>&lt;p&gt;In this blog post, we'll cover the basics of creating a heading element using JavaScript and how to append it to an existing element in your HTML document. This is a fundamental skill for manipulating the DOM (Document Object Model) and dynamically updating the content of your web pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Heading Element with JavaScript
&lt;/h2&gt;

&lt;p&gt;First, let's create a heading element using JavaScript. We'll use the &lt;code&gt;document.createElement&lt;/code&gt; method to create an &lt;code&gt;h1&lt;/code&gt; element and then set its content using &lt;code&gt;innerHTML&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here's how you can do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;document.createElement("h1")&lt;/code&gt;: This method creates an &lt;code&gt;h1&lt;/code&gt; element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Heading.innerHTML = "Hello World"&lt;/code&gt;: This line sets the inner HTML of the &lt;code&gt;h1&lt;/code&gt; element to "Hello World".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Appending the Heading to the Root Element
&lt;/h2&gt;

&lt;p&gt;Now that we've created our heading element, we need to append it to a specific part of our HTML document. Let's assume we have a &lt;code&gt;div&lt;/code&gt; element with the id &lt;code&gt;root&lt;/code&gt; in our HTML. We'll use the &lt;code&gt;getElementById&lt;/code&gt; method to select this element and then append our heading to it using &lt;code&gt;appendChild&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here's the complete code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;document.getElementById("root")&lt;/code&gt;: This method retrieves the element with the id &lt;code&gt;root&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;root.appendChild(Heading)&lt;/code&gt;: This line appends our heading element to the &lt;code&gt;root&lt;/code&gt; element.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By executing this code, the "Hello World" heading will be inserted into the &lt;code&gt;div&lt;/code&gt; with the id &lt;code&gt;root&lt;/code&gt;.&lt;/p&gt;

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