<?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: Puja Kundu</title>
    <description>The latest articles on DEV Community by Puja Kundu (@pujakundu).</description>
    <link>https://dev.to/pujakundu</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%2F575287%2F566474b0-0308-4ef2-9678-8f1394cbfdcd.jpg</url>
      <title>DEV Community: Puja Kundu</title>
      <link>https://dev.to/pujakundu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pujakundu"/>
    <language>en</language>
    <item>
      <title>Improving React App Performance with Lazy Loading</title>
      <dc:creator>Puja Kundu</dc:creator>
      <pubDate>Fri, 21 Apr 2023 16:54:19 +0000</pubDate>
      <link>https://dev.to/pujakundu/improving-react-app-performance-with-lazy-loading-577c</link>
      <guid>https://dev.to/pujakundu/improving-react-app-performance-with-lazy-loading-577c</guid>
      <description>&lt;p&gt;When building React applications, it's important to consider performance. Slow applications can have a negative impact on user experience, specially on slower internet connections. One technique for improving performance is lazy loading. &lt;br&gt;
According to the official documentation of React JS &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;lazy lets you defer loading component’s code until it is rendered for the first time.&lt;br&gt;
&lt;code&gt;const SomeComponent = lazy(load)&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Why and When to Use Lazy Loading
&lt;/h2&gt;

&lt;p&gt;Lazy loading can provide a number of benefits for your React application. By deferring or postponing the loading of non-critical components, one can reduce the initial bundle size and improve the time-to-interactive (a metric used to measure how long it takes for a web page to become fully interactive for the user).&lt;/p&gt;

&lt;p&gt;It is an effective technique to use when you have large or infrequently used components in your React application. For example, in a multi-step form with multiple sections, instead of loading all the code for each section upfront, you can use lazy loading to load each section's code only when the user needs it. This helps to reduce the initial load time of the application.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Use Lazy Loading in React
&lt;/h2&gt;

&lt;p&gt;To use lazy loading in React, you can use the lazy(load) function and the Suspense component.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lazy takes a parameter load which is a function that returns a promise. React will not execute the load function until the first time the returned component is rendered. Once React calls the load function, it will wait for it to resolve and then render the resolved value as a React component. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's an example of how you might use lazy loading to defer the loading of a component called MyComponent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { lazy, Suspense } from 'react';

const MyComponent = lazy(() =&amp;gt; import('./MyComponent'));

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
        &amp;lt;MyComponent /&amp;gt;
      &amp;lt;/Suspense&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the lazy() function is used to import the MyComponent module lazily, so that its code is only loaded when it's actually needed. The Suspense component is used to display a fallback UI while the code is being loaded. In this case, the fallback UI is simply the text "Loading...".&lt;/p&gt;

&lt;h2&gt;
  
  
  Disadvantages of Using Lazy Loading
&lt;/h2&gt;

&lt;p&gt;While lazy loading can provide significant performance benefits, it's important to use it judiciously and avoid overloading the browser with too many lazy-loaded components. Here are some potential disadvantages to consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Increased complexity:&lt;/strong&gt; Lazy loading adds an additional layer of complexity to your codebase, which can make it harder to understand and maintain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delayed rendering:&lt;/strong&gt; Because the code for lazy-loaded components is not loaded until it's needed, there may be a delay in rendering those components. This can result in a slower initial load time for the component.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Poor user experience on slow connections:&lt;/strong&gt; If a user is on a slow internet connection, lazy loading may result in a poor user experience, as components may take longer to load and render.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Lazy loading is a powerful technique for improving the performance of your React applications. Using it can lead to a faster and more responsive application and improve user experience. However, it's important to weigh the potential advantages and disadvantages of lazy loading to avoid overloading the browser with too many lazy-loaded components.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/reference/react/lazy"&gt;lazy&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>A brief intro to JS Promises</title>
      <dc:creator>Puja Kundu</dc:creator>
      <pubDate>Wed, 12 Oct 2022 14:33:34 +0000</pubDate>
      <link>https://dev.to/pujakundu/a-brief-intro-to-js-promises-5f1i</link>
      <guid>https://dev.to/pujakundu/a-brief-intro-to-js-promises-5f1i</guid>
      <description>&lt;p&gt;A JS Promise is an object that represents the completion or failure of an asynchronous operation and gives results. &lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;The syntax for writing a promise by using the ‘new’ keyword and promise constructor function.&lt;br&gt;
&lt;code&gt;const myPromise = new Promise();&lt;/code&gt;&lt;br&gt;
A promise has three states. That is -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pending&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resolved&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rejected&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pending:&lt;/strong&gt; When the state is ‘Pending’, it means the operation has neither been resolved nor rejected. Pending is the initial state, and the initial result is undefined.&lt;br&gt;
&lt;strong&gt;Resolved:&lt;/strong&gt; When the state is ‘Resolved’, it means the operation has been completed successfully and will give a result. &lt;br&gt;
&lt;strong&gt;Rejected:&lt;/strong&gt; When the state is ‘Rejected’, it means the operation has not been completed successfully and will give an error. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZB8PY07R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqpcg6xm9wi91bh811u3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZB8PY07R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqpcg6xm9wi91bh811u3.PNG" alt="Promise state" width="544" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to reject or fulfill a promise?
&lt;/h2&gt;

&lt;p&gt;For instance, you have an API where there is information such as product id, name, price, etc is stored. You make an API call. When you are making the API call, initially the state is pending and the promise has neither been resolved nor rejected. Now you want to show the data which in this case are the product pieces of information on the UI,  and if any error occurs you want to show an error message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--faGMAglX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uf61g78xhdxt1innkd98.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--faGMAglX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uf61g78xhdxt1innkd98.PNG" alt="State" width="625" height="275"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3CnxmVKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzhjvipcdm7k5xxm1vz2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3CnxmVKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzhjvipcdm7k5xxm1vz2.PNG" alt="States" width="622" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>React Higher Order Component</title>
      <dc:creator>Puja Kundu</dc:creator>
      <pubDate>Wed, 10 Aug 2022 18:48:21 +0000</pubDate>
      <link>https://dev.to/pujakundu/react-higher-order-component-13im</link>
      <guid>https://dev.to/pujakundu/react-higher-order-component-13im</guid>
      <description>&lt;h2&gt;
  
  
  What is a Higher Order Component in React?
&lt;/h2&gt;

&lt;p&gt;Higher order component is a function that takes a component as a parameter and returns an enhanced or changed component. Higher Order Component (HOC) adds additional data or functionality to the original component and returns an enhanced version of it.&lt;br&gt;
A HOC does not modify the original component. It takes the original component and wraps it in a container component. The wrapped component receives data and returns output according to the received data. A HOC is a pure function. &lt;/p&gt;
&lt;h2&gt;
  
  
  Why use a Higher Order Component?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HOC is used to share common functionalities between components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It helps to reduce code duplication&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Makes code manageable&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Let’s make a simple React application that will count the number of times you click on a button and hover on a text. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In your React app, create a folder named HOC. Inside the HOC folder, we will create a new file named ‘withCounter.js’. ‘withCounter.js’ is a Higher Order Component. ‘withCounter.js’ will contain the logic we need to build the counter system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, create another folder named ‘components’. Inside this folder create a component named ClickCounter.js.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

class ClickCounter extends React.Component {

  render() {

    return (
      &amp;lt;div&amp;gt;
        &amp;lt;button&amp;gt;Click me&amp;lt;/button&amp;gt;
        &amp;lt;p&amp;gt;Clicked X times&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

export default ClickCounter;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Inside the same folder create another component named HoverCounter.js
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

class HoverCounter extends React.Component {

  render() {

    return (
      &amp;lt;div&amp;gt;
        &amp;lt;h1&amp;gt;Hovered X times&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

export default HoverCounter;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As you can see in both the ClickCounter and HoverCounter components we have to create a state which will be increased by one each time we click the button or hover over a text. So let's write the logic to implement this functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; constructor(props) {
            super(props)
            this.state = {
                count:0
            }
        }

        incrementCount = () =&amp;gt; {
            this.setState(prevState =&amp;gt; {
                return {count: prevState.count + 1}
            })
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the initial state of count is set to zero and incrementCount will increment the value of count by 1.&lt;br&gt;
Now, one way to make the components work is by adding the above piece of code in both the components and trigger incrementCount on button click in ClickCounter and on mouse hover on HoverCounter.&lt;br&gt;
Another way is by using a Higher Order Component where we can put the count and incrementCount and then pass them down as props to ClickCounter and HoverCounter.&lt;br&gt;
To do that let's open our withCounter.js file and write some code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'

const UpdatedComponent = (OriginalComponent) =&amp;gt; {
    class NewComponent extends React.Component{
        constructor(props) {
            super(props)
            this.state = {
                count:0
            }
        }

        incrementCount = () =&amp;gt; {
            this.setState(prevState =&amp;gt; {
                return {count: prevState.count + 1}
            })
        }
        render(){
            return &amp;lt;OriginalComponent count={this.state.count} incrementCount={this.incrementCount } /&amp;gt;
        }
    }
    return NewComponent
}

export default UpdatedComponent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this HOC, UpdatedComponent is an arrow function that takes OriginalComponent as a parameter. In our case, we will send ClickCounter and HoverCounter as the OriginalComponent parameter.&lt;br&gt;
In this HOC, we are passing down count and incrementCount down as props in the OriginalComponent. Finally, we return NewComponent which, we can call an enhanced version of the OriginalComponent.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we will send ClickCounter and HoverCounter as parameters to the HOC withCounter.js. 
So, ClickCounter.js will be -
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

import UpdatedComponent from "../HOC/withCounter";

class ClickCounter extends React.Component {
  render() {
    const { count, incrementCount } = this.props;
    return (
      &amp;lt;div&amp;gt;
        &amp;lt;button onClick={incrementCount}&amp;gt;Click me&amp;lt;/button&amp;gt;
        &amp;lt;p&amp;gt;Hovered {count} times&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

export default UpdatedComponent(ClickCounter);

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And, HoverCounter.js will be
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import React from 'react'
import UpdatedComponent from "../HOC/withCounter";

class HoverCounter extends React.Component  {
  render() {
    const { count, incrementCount } = this.props;
    return (
      &amp;lt;div&amp;gt;
        &amp;lt;h1 onMouseOver={incrementCount}&amp;gt;Hovered {count} times&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }

};

export default UpdatedComponent(HoverCounter);

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

&lt;/div&gt;



&lt;p&gt;And, the final output is,&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%2Fltzohmwolmrepjsb42yn.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%2Fltzohmwolmrepjsb42yn.PNG" alt="HOC"&gt;&lt;/a&gt;&lt;br&gt;
Now, in this example, we can also solve the problem by lifting the state up to a common parent component. But in a larger application, if the counter components ClickCounter.js and HoverCounter.js are scattered, lifting state would not be the correct solution. In cases like this, we can use a Higher Order Component.&lt;br&gt;
So, this is how a Higher Order Component works.&lt;br&gt;
Thank You!!&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript(ES6) Symbols</title>
      <dc:creator>Puja Kundu</dc:creator>
      <pubDate>Tue, 21 Jun 2022 11:58:46 +0000</pubDate>
      <link>https://dev.to/pujakundu/javascriptes6-symbols-41l</link>
      <guid>https://dev.to/pujakundu/javascriptes6-symbols-41l</guid>
      <description>&lt;h2&gt;
  
  
  What is symbol in JavaScript?
&lt;/h2&gt;

&lt;p&gt;Symbol is a primitive data type that is unique and immutable. Every symbol has a hidden unique value. It is usually used to avoid name conflicts between object properties, and keys. &lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;Unlike other primitve data types, we can not create symbol with new keyword because symbol is not a constructor function. We can create a symbol by using the factory function Symbol(). It returns a unique symbol every time it is called.&lt;br&gt;
&lt;code&gt;var symbol = Symbol();&lt;/code&gt;&lt;br&gt;
We can also add description to symbols. Symbol description does not have any functional value. They are used for debugging purpose, to differentiate between symbols.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var symbol1 = Symbol();//Symbol with no description
var symbol2 = Symbol('Symbol description');//Symbol with description
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Symbols are unique
&lt;/h2&gt;

&lt;p&gt;Every time we create a new symbol in JavaScript, they return a unique value. Even though we get same output when we console.log symbol1 and symbol2, when we check if symbol1 is equal to symbol2 it returns false.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9tUXrDwg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvmmbd5prkvbkjhmmznm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9tUXrDwg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvmmbd5prkvbkjhmmznm.PNG" alt="Image description" width="415" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Symbol.for()
&lt;/h2&gt;

&lt;p&gt;Symbol.for(key) is an inbuilt method in JavaScript. It searches for existing symbols in runtime-wide registry with the given key and returns it. If it is not found, it creates a new symbol with the given key. The key can also be used as the description of the symbol.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qIEiYt9Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x24dyqkvpjhtaf7w2de6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qIEiYt9Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x24dyqkvpjhtaf7w2de6.PNG" alt="Image description" width="369" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Symbols?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can use symbols as object properties&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nXKKLwFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebn4dqh08pl5rlk4r7lm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nXKKLwFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebn4dqh08pl5rlk4r7lm.PNG" alt="Image description" width="561" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can use symbols to avoid over writing object properties
Say we have an object blackWidow with id and name properties. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GiSfNGwh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cc2o3qigipb65wajcac2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GiSfNGwh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cc2o3qigipb65wajcac2.PNG" alt="code" width="329" height="165"&gt;&lt;/a&gt;&lt;br&gt;
As we can see the value of id property is changed. What if we don’t want to change the actual value of id we can add symbol in the object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kACIUNg5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kiziwzv9r0c8kdcuicvq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kACIUNg5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kiziwzv9r0c8kdcuicvq.PNG" alt="code" width="444" height="162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symbols are hidden in loops and js functions. We can use them to keep any unique or identifier property hidden.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Am_Pjy23--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/21nb3cpx0qjjeilzfdrr.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Am_Pjy23--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/21nb3cpx0qjjeilzfdrr.PNG" alt="code" width="510" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is React Virtual DOM</title>
      <dc:creator>Puja Kundu</dc:creator>
      <pubDate>Wed, 20 Apr 2022 17:35:52 +0000</pubDate>
      <link>https://dev.to/pujakundu/react-virtual-dom-4f54</link>
      <guid>https://dev.to/pujakundu/react-virtual-dom-4f54</guid>
      <description>&lt;h2&gt;
  
  
  What is DOM?
&lt;/h2&gt;

&lt;p&gt;Document Object Model or simply DOM is an &lt;strong&gt;Application Programming Interface(API)&lt;/strong&gt; for HTML and XML documents. When a browser receives an HTML file, it parses it and builds a DOM tree. HTML elements are considered nodes in a DOM tree.&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%2Fpfe6bwvg0bnhd86oanh4.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%2Fpfe6bwvg0bnhd86oanh4.PNG" alt="DOM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Virtual DOM?
&lt;/h2&gt;

&lt;p&gt;Virtual DOM or VDOM is a virtual representation of the real DOM. It has the same properties as the real DOM but it can not directly change what’s on the screen. React uses virtual DOM. Why? We will get into that now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is the real DOM really slow?
&lt;/h2&gt;

&lt;p&gt;What is the first thing that comes to your mind when anybody asks why React uses Virtual DOM? What’s wrong with using the real DOM? - Well, it’s because the real DOM is really slow. &lt;/p&gt;

&lt;p&gt;Is it though?&lt;/p&gt;

&lt;p&gt;Adding or removing any element from DOM is actually pretty fast. Then why is it called slow?&lt;br&gt;
When we change something in a React component, that change has to be shown on the screen. The process of showing the changes in the UI is slow. &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%2F45sv1x5390h3tjnuzvsq.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%2F45sv1x5390h3tjnuzvsq.PNG" alt="Process"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upon receiving an HTML file, the browser render engine parses it and makes a &lt;strong&gt;DOM&lt;/strong&gt; tree. In the same way, the styles in the CSS file are parsed into &lt;strong&gt;CSSOM&lt;/strong&gt;. Both DOM and CSSOM make a render tree. The render tree has to go through a phase called &lt;strong&gt;Layout&lt;/strong&gt; .&lt;br&gt;
In the Layout phase, the coordinates of the elements of a render tree are found. The coordinates are used to determine the exact position where the elements will be shown on the screen. Lastly, in the &lt;strong&gt;Painting&lt;/strong&gt; phase, the elements are displayed on the screen. When we make any changes in a DOM, the browser has to build the render tree all over again. This repainting process is slow.&lt;/p&gt;

&lt;h2&gt;
  
  
  How virtual DOM works
&lt;/h2&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%2Fm3irfjgb6g5fxk7j2vt6.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%2Fm3irfjgb6g5fxk7j2vt6.PNG" alt="state change"&gt;&lt;/a&gt;&lt;br&gt;
Virtual DOM represents the same DOM elements. When we make any change in a react component, every single virtual DOM gets updated. Before updating the VDOM, a snapshot is taken. This snapshot is then compared to the updated virtual DOM to figure out which VDOM object has changed. This process is called &lt;strong&gt;diffing&lt;/strong&gt;. When react knows which object has changed, it updates only those objects in the real dom. These changes in the real DOM cause the screen to change.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Build a Rock-Paper-Scissors-Lizard-Spock game</title>
      <dc:creator>Puja Kundu</dc:creator>
      <pubDate>Tue, 08 Feb 2022 12:47:32 +0000</pubDate>
      <link>https://dev.to/pujakundu/build-a-rock-paper-scissors-lizard-spock-game-22n8</link>
      <guid>https://dev.to/pujakundu/build-a-rock-paper-scissors-lizard-spock-game-22n8</guid>
      <description>&lt;p&gt;If you are familiar with Big Bang Theory, you must have heard about the &lt;strong&gt;Rock-Paper-Scissors-Lizard-Spock&lt;/strong&gt; game. As Sheldon explains, "Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m3iSRybM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7vnwubwbho60huw482o.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m3iSRybM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7vnwubwbho60huw482o.gif" alt="Big Bang Theory CLip" width="500" height="219"&gt;&lt;/a&gt;&lt;br&gt;
Let's build this game with some HTML, CSS, and JavaScript.&lt;/p&gt;

&lt;p&gt;First, create an &lt;code&gt;index.html&lt;/code&gt; file and write some code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a container to hold the title and score.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="scoreboard"&amp;gt;
        &amp;lt;div class="title"&amp;gt;
          &amp;lt;h2&amp;gt;ROCK&amp;lt;/h2&amp;gt;
          &amp;lt;h2&amp;gt;PAPER&amp;lt;/h2&amp;gt;
          &amp;lt;h2&amp;gt;SCISSORS&amp;lt;/h2&amp;gt;
          &amp;lt;h2&amp;gt;LIZARD&amp;lt;/h2&amp;gt;
          &amp;lt;h2&amp;gt;SPOCK&amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="score"&amp;gt;
          &amp;lt;p&amp;gt;SCORE&amp;lt;/p&amp;gt;
          &amp;lt;h1&amp;gt;0&amp;lt;/h1&amp;gt;
        &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create another container to hold your rock, paper, scissors, lizard, and spock. Add click event &lt;code&gt;pickUserOption()&lt;/code&gt; on each image and pass parameters.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="options"&amp;gt;
        &amp;lt;div class="option spock"&amp;gt;
          &amp;lt;img src="/images/Spock.png" onclick="pickUserOption('spock')" /&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="option scissors"&amp;gt;
          &amp;lt;img
            src="/images/Scissors.png"
            onclick="pickUserOption('scissors')"
          /&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="option paper"&amp;gt;
          &amp;lt;img src="/images/Paper.png" onclick="pickUserOption('paper')" /&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="option lizard"&amp;gt;
          &amp;lt;img src="/images/Lizard.jpg" onclick="pickUserOption('lizard')" /&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="option rock"&amp;gt;
          &amp;lt;img src="/images/Rock.png" onclick="pickUserOption('rock')" /&amp;gt;
        &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally, show the results and play again button.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;div class="contest"&amp;gt;
        &amp;lt;div class="useroption"&amp;gt;
          &amp;lt;h1&amp;gt;YOU PICKED&amp;lt;/h1&amp;gt;
          &amp;lt;div class="optionImageContainer"&amp;gt;
            &amp;lt;img id="userPickImage" src="/images/Paper.png" /&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="result"&amp;gt;
          &amp;lt;div class="decision"&amp;gt;&amp;lt;h1&amp;gt;YOU WIN!&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;
          &amp;lt;div class="newGame" onclick="playAgainBtn()"&amp;gt;PLAY AGAIN&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="computeroption"&amp;gt;
          &amp;lt;h1&amp;gt;THE HOUSE PICKED&amp;lt;/h1&amp;gt;
          &amp;lt;div class="optionImageContainer"&amp;gt;
            &amp;lt;img id="computerPickImage" src="/images/Paper.png" /&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create your &lt;code&gt;main.js&lt;/code&gt; file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, let's add some fun sound effects and store image directories.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const clickSound = new Audio("/audio/mixkit-select-click-1109.wav");
const winSound = new Audio("/audio/mixkit-winning-notification-2018.wav");
const loseSound = new Audio("/audio/mixkit-losing-piano-2024.wav");

const userOptions = {
  rock: "/images/Rock.png",
  paper: "/images/Paper.png",
  scissors: "/images/Scissors.png",
  lizard: "/images/Lizard.jpg",
  spock: "/images/Spock.png",
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Write &lt;code&gt;pickUserOption()&lt;/code&gt; function that is called when you choose your option.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pickUserOption = (option) =&amp;gt; {
  let options = document.querySelector(".options");
  options.style.display = "none";

  let contest = document.querySelector(".contest");
  contest.style.display = "flex";

  clickSound.play();
  document.getElementById("userPickImage").src = userOptions[option];

  pickComputeroption(option);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;It's time for the Computer to pick its option. We generate some random number for the Computer to pick.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pickComputeroption = (option) =&amp;gt; {
  let options = ["rock", "paper", "scissors", "lizard", "spock"];
  let computerOption = options[Math.floor(Math.random() * 5)];

  // set computer image
  document.getElementById("computerPickImage").src =
    userOptions[computerOption];

  result(option, computerOption);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add a &lt;code&gt;play again&lt;/code&gt; button, &lt;code&gt;setDecision()&lt;/code&gt; function to show results and &lt;code&gt;setScore()&lt;/code&gt; function to update the score each time you win.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const playAgainBtn = () =&amp;gt; {
  let contest = document.querySelector(".contest");
  contest.style.display = "none";

  let options = document.querySelector(".options");
  options.style.display = "flex";
};

const setDecision = (decision) =&amp;gt; {
  document.querySelector(".decision h1").innerText = decision;
};

const setScore = (newScore) =&amp;gt; {
  SCORE = newScore;
  document.querySelector(".score h1").innerText = newScore;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Write another function that determines your fate, I mean the game results. It contains a bunch of if-else statements.🥱
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const result = (userOption, computerOption) =&amp;gt; {
  if (
    (userOption == "paper" &amp;amp;&amp;amp; computerOption == "scissors") ||
    (userOption == "paper" &amp;amp;&amp;amp; computerOption == "lizard")
  ) {
    setDecision("YOU LOSE!");
    playSound("lose");
  }
  if (
    (userOption == "paper" &amp;amp;&amp;amp; computerOption == "rock") ||
    (userOption == "paper" &amp;amp;&amp;amp; computerOption == "spock")
  ) {
    setDecision("YOU WIN!");
    setScore(SCORE + 1);
    playSound(win);
  }
  if (userOption == "paper" &amp;amp;&amp;amp; computerOption == "paper") {
    setDecision("It's a tie!");
    playSound("tie");
  }
..............
..............
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Last add another function to add some sound effects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const playSound = (result) =&amp;gt; {
  if (result == "win") {
    winSound.play();
  } else {
    loseSound.play();
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, write some CSS and add styling as per your likings.😊&lt;/p&gt;

&lt;p&gt;This is a FrontendMentor.io challenge. You can complete it &lt;a href="https://www.frontendmentor.io/challenges/rock-paper-scissors-game-pTgwgvgH"&gt;here&lt;/a&gt; &lt;br&gt;
See the full code &lt;a href="https://github.com/pujaKundu/rock-paper-scissor-lizard-spock"&gt;here&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>beginners</category>
      <category>html</category>
      <category>javascript</category>
    </item>
    <item>
      <title>JavaScript Hoisting</title>
      <dc:creator>Puja Kundu</dc:creator>
      <pubDate>Fri, 23 Jul 2021 09:47:51 +0000</pubDate>
      <link>https://dev.to/pujakundu/javascript-hoisting-330f</link>
      <guid>https://dev.to/pujakundu/javascript-hoisting-330f</guid>
      <description>&lt;p&gt;Hoisting is a default behaviour of JavaScript. It moves the declaration of variables and functions to the top of the current scope (script or function). In that way, a variable can be declared after it has been used and a function can be called before it is even written .&lt;br&gt;
For example , the given code will not show any error ,by default var x will be moved before x = 20.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;x = 20;&lt;br&gt;
console.log(x);&lt;br&gt;
var x;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output: 20&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But this will only work if we use the &lt;strong&gt;var&lt;/strong&gt; keyword. &lt;/p&gt;

&lt;h3&gt;
  
  
  Only declarations are hoisted , not initializations:
&lt;/h3&gt;

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

&lt;p&gt;&lt;code&gt;var x = 5;//Initialize x&lt;br&gt;
console.log(`The values of x and y are: ${x} and ${y}`);&lt;br&gt;
var y = 9;//Initialize y , won’t be hoisted&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output : The values of x and y are: 5 and undefined&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The ‘let’ and ‘const’ keyword :
&lt;/h3&gt;

&lt;p&gt;The variables declared with &lt;strong&gt;let&lt;/strong&gt; and &lt;strong&gt;const&lt;/strong&gt; keyword are hoisted to the top but will not work because they are not initialized.&lt;/p&gt;

&lt;h4&gt;
  
  
  The let keyword will cause ReferenceError :
&lt;/h4&gt;

&lt;p&gt;Reference Error occurs when a non-existent variable is referenced. The variable declared with &lt;strong&gt;'let'&lt;/strong&gt; keyword will be considered non-existent until it is declared.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;y = 10;&lt;br&gt;
console.log(y);&lt;br&gt;
let y;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output : ReferenceError: Cannot access 'y' before initialization&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The const keyword will cause SyntaxError :
&lt;/h4&gt;

&lt;p&gt;Using the &lt;strong&gt;'const'&lt;/strong&gt; keyword is considered as Syntax Error. So the code will not run.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;y = 10;&lt;br&gt;
console.log(y);&lt;br&gt;
const y;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output : SyntaxError: Missing initializer in const declaration&lt;/strong&gt;&lt;/p&gt;

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