<?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: Vansh Sharma</title>
    <description>The latest articles on DEV Community by Vansh Sharma (@vanshsh).</description>
    <link>https://dev.to/vanshsh</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%2F643916%2F133ad454-7f0c-435c-8d91-fb5185293c6c.jpeg</url>
      <title>DEV Community: Vansh Sharma</title>
      <link>https://dev.to/vanshsh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vanshsh"/>
    <language>en</language>
    <item>
      <title>useReducer Hook in React</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Tue, 10 May 2022 13:23:07 +0000</pubDate>
      <link>https://dev.to/vanshsh/usereducer-hook-in-react-5h5h</link>
      <guid>https://dev.to/vanshsh/usereducer-hook-in-react-5h5h</guid>
      <description>&lt;p&gt;Welcome back again!&lt;/p&gt;

&lt;p&gt;This is the fifth blog in the &lt;strong&gt;React Hook&lt;/strong&gt; series, where we're learning about different hooks used in React, and today's hook is the &lt;code&gt;useReducer&lt;/code&gt; hook. Before we get started, I'd recommend reading the last blogs of this series &lt;a href="https://vanshsharma.hashnode.dev/series/react-hooks"&gt;React Hooks&lt;/a&gt;. Though this hook is entirely independent of we can read and learn it without any prior knowledge of hooks, it would be beneficial to have some basic understanding of the hooks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is useReducer Hook
&lt;/h2&gt;

&lt;p&gt;To handle the complex state in our application, we use the &lt;code&gt;useReducer&lt;/code&gt; hook. It is the same as the &lt;code&gt;useState&lt;/code&gt; hook, but instead, it is used to handle the states where we have to keep track of the complex states which rely on the complex logic.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Syntax:&lt;/p&gt;

&lt;p&gt;useReducer(reducerFn, initialState )&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reducerFn is the function that contains the logic to handle the manipulation of our state.&lt;/li&gt;
&lt;li&gt;initialState is the initial state value of our state. It is primarily objects while using the &lt;code&gt;useReducer&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;useReducer&lt;/code&gt; hooks return the two values:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const [ state, dispatch ] = useReducer ( reducerFn, initialState )&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the &lt;strong&gt;&lt;em&gt;state&lt;/em&gt;&lt;/strong&gt; is  the value of the current state&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;dispatch&lt;/em&gt;&lt;/strong&gt;  is the method that will be used to call our &lt;code&gt;reducerFn&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Understand useReducer by Example
&lt;/h2&gt;

&lt;p&gt;In the following example, we will create a simple app that will display the user's &lt;em&gt;Name&lt;/em&gt; and &lt;em&gt;Account Number&lt;/em&gt;. We will be using &lt;code&gt;useReducer&lt;/code&gt; for this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 =&amp;gt; Import the  useReducer Hook
&lt;/h3&gt;

&lt;p&gt;Import the &lt;code&gt;useReducer&lt;/code&gt; hook and define it in the component.&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, { useReducer } from "react";

const UseReducer = () =&amp;gt; {
  const [userData, dispatchData] = useReducer(userReducer, {
    userName: "Please Login!",
    userAccount: null
  });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;userData&lt;/code&gt; will be our value of the state then, and the initial value of the state will be an object with properties &lt;code&gt;userName&lt;/code&gt; and &lt;code&gt;userAccount&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;dispatchData&lt;/code&gt; will be the method to call the &lt;code&gt;userReducer&lt;/code&gt; function, which we will define in the coming section.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2 =&amp;gt; Define userReducer function:
&lt;/h3&gt;

&lt;p&gt;We can define the &lt;code&gt;userReducer&lt;/code&gt; function outside our component since all the values will be passed using the &lt;code&gt;dispatchData&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Reducer function

const userReducer = (state, action) =&amp;gt; {
  if (action.type === "LOGIN") {
    return {
      userName: action.data.name,
      userAccount: action.data.account
    };
  }
  if (action.type === "LOGGED_OUT") {
    return {
      userName: "You are logged out!",
      userAccount: null
    };
  }
};

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;userReducer&lt;/code&gt; function will take two arguments &lt;em&gt;state&lt;/em&gt; and &lt;em&gt;action&lt;/em&gt;. &lt;em&gt;state&lt;/em&gt; is the value of the state then, and &lt;em&gt;action&lt;/em&gt; is used to check for what action which &lt;em&gt;if condition&lt;/em&gt; to render, and this &lt;code&gt;type&lt;/code&gt; will be passed by the &lt;code&gt;dispatchData&lt;/code&gt; method that we will define in the coming section.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 =&amp;gt; Add the UI for the Application
&lt;/h3&gt;

&lt;p&gt;We will create the UI for the application that will show the &lt;code&gt;userName&lt;/code&gt; and &lt;code&gt;userAccount&lt;/code&gt; numbers along with two buttons. One of them is to handle the login function and will call the &lt;code&gt;loginHandler&lt;/code&gt; function once clicked, and the other button will handle the &lt;code&gt;logoutHandler&lt;/code&gt; function.&lt;br&gt;
Here is how the code for the UI will look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
    &amp;lt;div className="component"&amp;gt;
      &amp;lt;p&amp;gt;{userData.userName}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;{userData.userAccount}&amp;lt;/p&amp;gt;
      &amp;lt;div className="btns"&amp;gt;
        &amp;lt;button onClick={loginHandler}&amp;gt;Login&amp;lt;/button&amp;gt;
        &amp;lt;button onClick={logoutHandler}&amp;gt;Logout&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4 =&amp;gt; Define the loginHandler and logoutHandler functions
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;loginHandler&lt;/code&gt; and &lt;code&gt;logoutHandler&lt;/code&gt; functions will use the &lt;code&gt;dispatchData&lt;/code&gt; method to pass the object with property &lt;code&gt;type&lt;/code&gt; and user details. The &lt;code&gt;type&lt;/code&gt; will have the value &lt;code&gt;LOGIN&lt;/code&gt; and which we will use in our &lt;code&gt;userReducer&lt;/code&gt; function to call the specific if statement according to the value of the &lt;code&gt;type&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Login Handler
  const loginHandler = () =&amp;gt; {
    dispatchData({
      type: "LOGIN",
      data: {
        name: "Hello Vansh Sharma",
        account: "Your account number is: 123456"
      }
    });
  };

  // Logout Handler
  const logoutHandler = () =&amp;gt; {
    dispatchData({
      type: "LOGOUT"
    });
  };

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

&lt;/div&gt;



&lt;p&gt;Combining the above all code snippets in the following codesandbox we get the following application:&lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/usereducer-d47vmc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Check the &lt;code&gt;UseReducer.js&lt;/code&gt; to understand more.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  When to use useReducer
&lt;/h3&gt;

&lt;p&gt;As you can see the, setting up &lt;code&gt;useReducer&lt;/code&gt; is more lengthy than using the &lt;code&gt;useState&lt;/code&gt; hook; therefore prefer using the &lt;code&gt;useReducer&lt;/code&gt; only if the state of the component depends on the complex function or the state of the component is complicated, like an object with many properties.&lt;/p&gt;

&lt;p&gt;That's all for this blog.  Continue reading this React hook series to learn more about React hooks. In the next blog, we'll look at the &lt;code&gt;useCallback&lt;/code&gt; hook that can be used to memorize the function.&lt;br&gt;
Feel free to leave your valuable feedback in the comments below.&lt;/p&gt;

&lt;p&gt;To learn more about React, JavaScript, and Web development, follow me on :&lt;br&gt;
&lt;a href="https://twitter.com/Vanshsh2701"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--opAxX3tY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/Twitter-1DA1F2%3Fstyle%3Dfor-the-badge%26logo%3Dtwitter%26logoColor%3Dwhite" alt="" width="100" height="28"&gt;&lt;/a&gt; &lt;a href="https://www.linkedin.com/in/vanshsharma27/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--imBRhTaX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/LinkedIn-0077B5%3Fstyle%3Dfor-the-badge%26logo%3Dlinkedin%26logoColor%3Dwhite" alt="" width="107" height="28"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://www.w3schools.com/react/react_usereducer.asp"&gt;W3Schools&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>hooks</category>
    </item>
    <item>
      <title>useRef Hook in React</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Sun, 01 May 2022 13:58:59 +0000</pubDate>
      <link>https://dev.to/vanshsh/useref-hook-in-react-436b</link>
      <guid>https://dev.to/vanshsh/useref-hook-in-react-436b</guid>
      <description>&lt;p&gt;Welcome back again!&lt;/p&gt;

&lt;p&gt;This is the fourth blog in the &lt;strong&gt;React Hook&lt;/strong&gt; series, where we're learning about different hooks used in React, and our today's hook is the &lt;code&gt;useRef&lt;/code&gt; hook. Before we get started, I'd recommend reading the last blogs of this series &lt;a href="https://vanshsharma.hashnode.dev/series/react-hooks"&gt;React Hooks&lt;/a&gt;. Though this hook is completely independent of we can read and learn it without any prior knowledge of hooks, it would be beneficial to have some basic understanding of the hooks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is useRef Hook
&lt;/h2&gt;

&lt;p&gt;We can build a direct reference to a DOM element using the &lt;code&gt;useRef&lt;/code&gt; hooks. It's used to keep track of mutable values that do not cause re-rendering every time they're changed. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Syntax:&lt;/p&gt;

&lt;p&gt;const refContainer = useRef(intialValue)&lt;/p&gt;

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

&lt;p&gt;const  countRef = useRef(0)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;useRef&lt;/code&gt; returns a mutable object whose &lt;code&gt;current&lt;/code&gt; property can be used to access the value.&lt;br&gt;
In the above syntax, we have initialized the &lt;code&gt;useRef&lt;/code&gt; with the initial value of 0.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const countRef = {counter:0} is same as  const count = useRef(0)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Difference between useState and useRef
&lt;/h2&gt;

&lt;p&gt;We can see in the following codesandbox that using the &lt;code&gt;useRef&lt;/code&gt; we can persist the previous value on every render. But using the same with &lt;code&gt;useState&lt;/code&gt; is not possible.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/useref-67qk9h"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantage of using useRef
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It allows us to directly access the DOM element without causing any issue.&lt;/li&gt;
&lt;li&gt;Values updated using &lt;code&gt;useRef&lt;/code&gt; do not cause re-rendering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Ending
&lt;/h2&gt;

&lt;p&gt;That's all for this blog.  Continue reading this React hook series to learn more about React hooks. In the next blog, we'll look at the 'useReducer' hook, which is used to handle state management in React globally.&lt;br&gt;
Feel free to leave your valuable feedback in the comments below.&lt;/p&gt;

&lt;p&gt;To learn more about React, JavaScript, and Web development, follow me on &lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Reference: W3Schools&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>useContext Hook in React</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Tue, 26 Apr 2022 12:19:46 +0000</pubDate>
      <link>https://dev.to/vanshsh/usecontext-hook-in-react-2d7e</link>
      <guid>https://dev.to/vanshsh/usecontext-hook-in-react-2d7e</guid>
      <description>&lt;p&gt;Welcome back again!&lt;/p&gt;

&lt;p&gt;This is the third blog in the &lt;strong&gt;React Hook&lt;/strong&gt; series, where we're learning about different hooks used in React, and our today's hook is the &lt;code&gt;useContext&lt;/code&gt; hook. Before we get started, I'd recommend reading the last blogs of this series &lt;a href="https://vanshsharma.hashnode.dev/series/react-hooks"&gt;React Hooks&lt;/a&gt; . Though this hook is completely independent of we can read and learn it without any prior knowledge of hooks, it would be beneficial to have some basic understanding of the hooks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the useContext Hook
&lt;/h2&gt;

&lt;p&gt;Until now, we've learned that if we need to pass state from one component to another, we must do so via props.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This method of passing the state through the props is called prop drilling.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, passing the state with props is only useful for small applications; as our application grows in size, the number of components grows as well, making prop drilling ineffective.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;useContext&lt;/code&gt; hook comes to our rescue because it offers state at a global level, making it simple to give state directly to the component rather than passing it through many components.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OZ7Zd76b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650639220464/AGeHeuV2S.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OZ7Zd76b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1650639220464/AGeHeuV2S.png" alt="Props Drilling and useContext.png" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Example of Prop Drilling
&lt;/h2&gt;

&lt;p&gt;Though the state was not necessary for the &lt;code&gt;ComponentB&lt;/code&gt; and &lt;code&gt;ComponentC&lt;/code&gt; in the following widget, this is the only way to move the state from one component to another without using the &lt;code&gt;useContext&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/propdrilling-x28150"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Use useContext Hook
&lt;/h2&gt;

&lt;p&gt;We're going to make a simple counter app with three components, each of which will update the global state of the &lt;code&gt;counter&lt;/code&gt;. The three components are &lt;code&gt;Increase&lt;/code&gt;, &lt;code&gt;Decrease&lt;/code&gt;, and &lt;code&gt;Reset&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;useContext&lt;/code&gt; will be used for all of this state updating and providing count value back to the components. &lt;/p&gt;

&lt;p&gt;Easy method to remember the flow of &lt;code&gt;useContext&lt;/code&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Create &amp;gt; Provide &amp;gt; Use&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we will learn step by step to use and create &lt;code&gt;useContext&lt;/code&gt; :&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1 (Create)
&lt;/h3&gt;

&lt;p&gt;Always prefer to create a separate &lt;code&gt;Context.js&lt;/code&gt; file in the &lt;code&gt;src&lt;/code&gt; folder to use the &lt;code&gt;useContext&lt;/code&gt;.&lt;br&gt;
As told in the above flow, our first step would be to create the &lt;code&gt;useContext&lt;/code&gt; hook. In the following snippet, we will &lt;code&gt;import&lt;/code&gt; the different hooks and function to create the context. We use &lt;code&gt;createContext&lt;/code&gt; function to create the context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Context.js

import React, { useState, createContext, useContext } from "react";

const CounterContext = createContext();

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2 (Provide)
&lt;/h3&gt;

&lt;p&gt;Now we will use the above  &lt;code&gt;CounterContext&lt;/code&gt; and wrap our whole application to provide the values to every component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Context.js

export const NameContextProvider = ({ children }) =&amp;gt; {
  const [counter, setCounter] = useState(0);
  return (
    &amp;lt;CounterContext.Provider value={{ counter, setCounter }}&amp;gt;
      {children}
    &amp;lt;/CounterContext.Provider&amp;gt;
  );
};


// index.js

import { NameContextProvider } from "./Context";
import App from "./App";

const rootElement = document.getElementById("root");
ReactDOM.render(
    &amp;lt;NameContextProvider&amp;gt;
      &amp;lt;App /&amp;gt;
    &amp;lt;/NameContextProvider&amp;gt;,
  rootElement
);


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

&lt;/div&gt;



&lt;p&gt;Because we wrapped our application in the &lt;code&gt;index.js&lt;/code&gt; file using the &lt;code&gt;NameContextProvider&lt;/code&gt;, &lt;code&gt;children&lt;/code&gt; will be our application in the above snippet. To build the state, we're using a simple &lt;code&gt;useState&lt;/code&gt; hook. The component &lt;code&gt;Provider&lt;/code&gt; in the &lt;code&gt;CounterContext.Provider&amp;gt;&amp;lt;/CounterContext.Provider&amp;gt;&lt;/code&gt; helps the context deliver state values to all the components that have been wrapped around. The value of all the states and functions that we want to share with components is referred to as &lt;code&gt;value&lt;/code&gt; In the  &lt;code&gt;value&lt;/code&gt; field, we can put anything we want.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 (Use)
&lt;/h3&gt;

&lt;p&gt;Now the last step is using the context we have created using the &lt;code&gt;useContext&lt;/code&gt; hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const UseCounterContext = () =&amp;gt; useContext(CounterContext);

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Always remember to export the &lt;code&gt;UseCounterContext&lt;/code&gt; and &lt;code&gt;NameContextProvider&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These were the steps for creating the context.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now all we have to do is create the various components and use this state value to update the state value as needed.
We'll make three separate components: one to increase the value, one to decrease the value, and one to reset the state's value to zero.
I will show only one component in the following snippet all other components will follow the same method with some changes in the state updating function &lt;code&gt;setCounter&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Increase.js

import { UseCounterContext } from "./Context";

const Increase = () =&amp;gt; {

  const { counter, setCounter } = UseCounterContext();

  const increaseHandler = () =&amp;gt; {
    setCounter((prevValue) =&amp;gt; prevValue + 1);
  };

  return (
    &amp;lt;div className="component"&amp;gt;
      &amp;lt;h3&amp;gt;I am counter {counter} in ComponentA&amp;lt;/h3&amp;gt;
      &amp;lt;button onClick={increaseHandler}&amp;gt;Increase&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Increase;


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

&lt;/div&gt;



&lt;p&gt;To utilize the value of the context we have to import the &lt;code&gt;UseCounterContext&lt;/code&gt; which we created in Step 3 (Use) of the context. After importing the &lt;code&gt;UseCounterContext&lt;/code&gt; we will destructure all the values passed in values in the &lt;code&gt;Context.js&lt;/code&gt; file. Since we passed the &lt;code&gt;counter&lt;/code&gt; and &lt;code&gt;setCounter&lt;/code&gt; and we need only these values in our component so we will destructure these values and use them in the component.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: We can destructure only those values that we are going to use in the particular component.&lt;br&gt;
Since the above snippet is for &lt;code&gt;Increase.js&lt;/code&gt; component we will increase the value of the &lt;code&gt;counter&lt;/code&gt; using the &lt;code&gt;setCounter&lt;/code&gt; function.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create the &lt;code&gt;Decrease.js&lt;/code&gt; and &lt;code&gt;Reset.js&lt;/code&gt; functions similarly.&lt;br&gt;
Here is the final codesandbox.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/usecontext-application-1dy7w8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Ending
&lt;/h2&gt;

&lt;p&gt;Always remember to follow the flow of the context ie &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Create &amp;gt; Provide  &amp;gt; Use&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's all for this blog.  Continue reading this React hook series to learn more about React hooks. In the next blog, we'll look at the 'useContext' hook, which is used to handle state management in React globally.&lt;br&gt;
Feel free to leave your valuable feedback in the comments below.&lt;/p&gt;

&lt;p&gt;To learn more about React, JavaScript, and Web development, follow me on &lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Reference: W3Schools&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>useEffect hook in React</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Tue, 19 Apr 2022 15:02:39 +0000</pubDate>
      <link>https://dev.to/vanshsh/useeffect-hook-in-react-mgc</link>
      <guid>https://dev.to/vanshsh/useeffect-hook-in-react-mgc</guid>
      <description>&lt;p&gt;Welcome back!&lt;/p&gt;

&lt;p&gt;This is the second blog in the &lt;strong&gt;React Hook&lt;/strong&gt; series, where we're learning about different hooks used in React, and our today's hook is the &lt;code&gt;useEffect&lt;/code&gt; hook. Before we get started, I'd recommend reading the last blog of this series &lt;a href="https://vanshsharma.hashnode.dev/react-usestate-hook"&gt;useState Hook&lt;/a&gt;. Though this hook is completely independent of the &lt;code&gt;useState&lt;/code&gt; hook, and you can read and learn from it without any prior knowledge of hooks, it would beneficial to have some basic understanding of the hooks.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the use of useEffect hook in React?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;useEffect&lt;/code&gt; hook is used in our components to perform side effects. Side effects are the task that happens outside the normal component evaluation. Data fetching, web API, and manually changing the DOM are some examples of side effects. &lt;/p&gt;

&lt;h3&gt;
  
  
  How to use the useEffect hook
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Import useEffect hook&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can be imported by destructuring from the React library using the following 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 {useEffect} from "react"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Syntax of useEffect hook
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect (  &amp;lt;function&amp;gt; , [dependency] )

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

&lt;/div&gt;



&lt;p&gt;There are two arguments:&lt;/p&gt;

&lt;p&gt;(i) The first is a function that will be invoked on every render until the &lt;code&gt;dependence&lt;/code&gt; is provided.&lt;/p&gt;

&lt;p&gt;(ii) The second argument is the  &lt;code&gt;dependence&lt;/code&gt; which will enable &lt;code&gt;useEffect&lt;/code&gt; to call our specified function if it changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why use dependency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As previously stated, the &lt;code&gt;useEffect&lt;/code&gt; hook will call our function on every render, resulting in an infinite loop and crashing the browser. However, there are ways to avoid it by providing dependency.&lt;/p&gt;

&lt;p&gt;1) Providing an empty array [] as a dependency&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useEffect( () =&amp;gt;{

// it will run only on the first render

},[]}

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

&lt;/div&gt;



&lt;p&gt;2) Providing the props or state as the dependencies&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect( () =&amp;gt;{

// it will run on the first render
// it will also run every time the given dependencies changes

},[  props , state  ]}

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

&lt;/div&gt;



&lt;p&gt;Check out the file &lt;code&gt;NonEmptyDependency.js&lt;/code&gt;, and &lt;code&gt;EmptyDependency.js&lt;/code&gt;. and console of the following codesandbox to better understand the examples.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/useeffect-hook-with-empty-dependency-3pfwjs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Cleanup function in useEffect
&lt;/h3&gt;

&lt;p&gt;Consider the following scenario: we obtain a fetch of a specific user via the user's id, but before the fetch is completed, we change our minds and attempt to obtain another user. While the previous retrieve request is still in progress, the prop, or in this example, the id, updates.&lt;br&gt;
To avoid exposing our application to a memory leak, we must then cancel the fetch using the cleanup function.&lt;br&gt;
Every time the &lt;code&gt;useEffect&lt;/code&gt; is called the cleanup function will also run except on the first render.&lt;/p&gt;

&lt;p&gt;Let us clean the Timeout function at the end of the &lt;code&gt;useEffect&lt;/code&gt; hook in the following codesandbox.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/useeffect-cleanup-function-12keoy"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That's all for this blog.  Continue reading this React hook series to learn more about React hooks. In the next blog, we'll look at the 'useContext' hook, which is used to handle state management in React globally.&lt;br&gt;
Feel free to leave your valuable feedback in the comments below.&lt;/p&gt;

&lt;p&gt;To learn more about React, JavaScript, and Web development, follow me on &lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Reference: W3Schools, &lt;a href="https://blog.logrocket.com/understanding-react-useeffect-cleanup-function/#:~:text=The%20cleanup%20function%20prevents%20memory,some%20unnecessary%20and%20unwanted%20behaviors."&gt;Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>hooks</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React useState hook</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Tue, 12 Apr 2022 17:05:03 +0000</pubDate>
      <link>https://dev.to/vanshsh/react-usestate-hook-1jcf</link>
      <guid>https://dev.to/vanshsh/react-usestate-hook-1jcf</guid>
      <description>&lt;p&gt;Before we get into the core of the article, let's go over some key details around React hooks.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are Hooks?
&lt;/h3&gt;

&lt;p&gt;Hooks were introduced in the React version 16.8. Hooks are the functions that let the user have access to the state and lifecycle method in the function component. Before the hooks were introduced in React, the &lt;code&gt;class&lt;/code&gt; component was the only option to access the state and lifecycle methods.  Even though &lt;code&gt;class&lt;/code&gt; components are no longer required, they can still be found in some legacy code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are no plans to remove classes from React — we all need to keep shipping products and can’t afford rewrites. We recommend trying Hooks in new code. &lt;a href="https://reactjs.org/docs/hooks-faq.html#do-i-need-to-rewrite-all-my-class-components"&gt;React doc&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Rules for using hooks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Hooks can only be used with function components.&lt;/li&gt;
&lt;li&gt;Hooks can not be conditional like inside the &lt;code&gt;if...else&lt;/code&gt;, &lt;code&gt;switch&lt;/code&gt; statements.&lt;/li&gt;
&lt;li&gt;Hooks must only be called at the top level of a component.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  React useState Hook
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; hook allows us to track the information of the component between the rendering of the component such information is called the state of the component. State is like the value of the variable declared within the function.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to use useState
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Import useState hook&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As &lt;code&gt;useState&lt;/code&gt; hook is the named export in the React library we can easily import it by destructuring from the React.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;How to initialize &lt;code&gt;useState&lt;/code&gt; hook&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; hook is initialized on the top of the component by calling in our function component.&lt;/p&gt;

&lt;p&gt;Here again, we are destructuring the returning value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Counter = () =&amp;gt; {

const [count , setCount ] = useState(0)

}

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

&lt;/div&gt;



&lt;p&gt;It returns the two values :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; "count" is the current state.&lt;/li&gt;
&lt;li&gt; "setCount" is the function that is used to update our state.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Common naming convention for the &lt;code&gt;useState&lt;/code&gt; hook is:&lt;/p&gt;

&lt;p&gt;[ variable , setVariable ] = useState() &lt;/p&gt;

&lt;p&gt;Here "variable"  can be anything.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, we give the initial state to the hook, which can be anything from &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;array&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;, or any combination of these. In our case, it is the &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Initial state =  useState(0)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt; How to read the state &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our first returning value will be the value of the state. We can use it anywhere in our component to read the state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Counter = () =&amp;gt; {

const [count , setCount ] = useState(0)

return (

&amp;lt;h1&amp;gt; Current value is  {count} &amp;lt;/h1&amp;gt;

)}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;How to update the state &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can only update the value of the state using the function returned by the &lt;code&gt;useState&lt;/code&gt; hook in this case &lt;code&gt;setCount&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Never update the state directly. Example: count= 25 .&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function increaseCount(){

setCount( prevValue =&amp;gt; prevValue+1 )

}

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

&lt;/div&gt;



&lt;p&gt;Combining the above all code snippets, we get the following codesandbox. Check the &lt;code&gt;App.js&lt;/code&gt; file of the following codesandbox.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/usestate-hook-0u4bfp"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Update the Objects in the State
&lt;/h3&gt;

&lt;p&gt;In the above section we discussed how to update the numbers in the state but as explained earlier that &lt;code&gt;useState&lt;/code&gt; can take  &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;array&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;, or any combination of these as the state. So now in the following points, we will learn How to update the Objects in the state?&lt;br&gt;
When the component's state is updated, the entire state of the component is fully overwritten. However, while using objects in the state, we simply want to update the object's specific property and leave the rest of the properties unchanged.&lt;/p&gt;

&lt;p&gt;Let's look at how the state update entirely replaces the prior state without using the previous values from the state. &lt;br&gt;
Here in the function &lt;code&gt;withoutPrevious&lt;/code&gt; we update the &lt;code&gt;lastName&lt;/code&gt; property to "Bhardwaj".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function User() {

  // Update without prev values

  const [user, setUser] = useState({
    firstName: "Vansh",
    lastName: "Sharma",
    city: "Delhi"
  });

//  Function to update without prev value
  const withoutPrevious = () =&amp;gt; {
    setUser((prev) =&amp;gt; {
      return { lastName: "Bhardwaj" };
    });
  };

return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h3&amp;gt;
        I am {user.firstName} {user.lastName} from {user.city}.
      &amp;lt;/h3&amp;gt;

      &amp;lt;button onClick={withoutPrevious}&amp;gt;
        Update last name without previous values.
      &amp;lt;/button&amp;gt;

}

// Original  I am Vansh Sharma from Delhi.

// Output  I am Bhardwaj from.

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

&lt;/div&gt;



&lt;p&gt;Now let us look at how to update only the specific property of the object and retaining the actual value of all other properties.&lt;br&gt;
Unlike in the above function here to update the &lt;code&gt;lastName&lt;/code&gt; in the function &lt;code&gt;withPrevious&lt;/code&gt; we have used the spread operator to spread the previous value in the new state and overwriting only the &lt;code&gt;lastName&lt;/code&gt; property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function User() {

  //  Update with prev values
  const [user1, setUser1] = useState({
    firstName: "Vansh",
    lastName: "Sharma",
    city: "Delhi"
  });

   // Function to update with prev values
  const withPrevious = () =&amp;gt; {
    setUser1((prev) =&amp;gt; {
      return { ...prev, lastName: "Bhardwaj" };
    });
  };

  return (
    &amp;lt;div className="App"&amp;gt;

        I am {user1.firstName} {user1.lastName} from {user1.city}.
      &amp;lt;/h3&amp;gt;

      &amp;lt;button onClick={withPrevious}&amp;gt;
        Update last name with previous values.
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

// Original  I am Vansh Sharma from Delhi.

// Output  I am Vansh Bhardwaj from Delhi.

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

&lt;/div&gt;



&lt;p&gt;Check out the codesandbox of the above code here. Do check out the &lt;code&gt;App.js&lt;/code&gt; file in the following codesandbox.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/objects-in-the-state-e77xfc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That's all for this blog.  Continue reading this React hook series to learn more about React hooks. In the next blog, we'll look at the 'useEffect' hook, which can be used to handle side effect functions in React.&lt;br&gt;
Feel free to leave your valuable feedback in the comments below.&lt;/p&gt;

&lt;p&gt;To learn more about React, JavaScript, and Web development, follow me on &lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Reference: W3Schools&lt;/p&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Functions in JavaScript</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Sun, 09 Jan 2022 08:31:42 +0000</pubDate>
      <link>https://dev.to/vanshsh/functions-in-javascript-5eda</link>
      <guid>https://dev.to/vanshsh/functions-in-javascript-5eda</guid>
      <description>&lt;p&gt;In this blog, we will learn about &lt;strong&gt;functions&lt;/strong&gt; like any other programming language &lt;em&gt;JavaScript&lt;/em&gt; also has functions that help us to perform the same task again and again without writing the same code again. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. Function
&lt;/h2&gt;

&lt;p&gt;​Syntax: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kZnk8zS8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641568821397/LtStgJt5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kZnk8zS8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641568821397/LtStgJt5t.png" alt="carbon.png" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;functionName = Name of the function (add, sub etc.) &lt;/p&gt;

&lt;p&gt;para1, para2 = Parameters&lt;/p&gt;

&lt;p&gt;functionName( arg1 ,arg2 ) = Function calling &lt;/p&gt;

&lt;p&gt;arg1 , arg2 = Arguments&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The function call is used to execute the code inside the function body. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Hoisting&lt;/em&gt;&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is the JavaScript feature that allows us to call the function before it is declared.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: Arrow function does not support Hoisting.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wl8rX7yJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641568912483/hHQDm4QwC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wl8rX7yJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641568912483/hHQDm4QwC.png" alt="carbon (2).png" width="880" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Argument VS Parameter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most of the time developers use both these words interchangeably. However, they are different.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Arguments&lt;/em&gt;&lt;/strong&gt; are the values that you pass while calling the function.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Parameters&lt;/em&gt;&lt;/strong&gt; are the values that you give while defining the function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CNbf4ENb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641570991397/sYYyPi7vw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CNbf4ENb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641570991397/sYYyPi7vw.png" alt="carbon (6).png" width="880" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*** First-Class Citizens***&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript functions are First-Class-Citizens that means you can store functions in variables, you can pass them into another function as an argument, you can also return another function as a return value.&lt;/p&gt;

&lt;p&gt;a. Store function as a variable&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--deWXMS6L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641569258912/hFuoHNzGu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--deWXMS6L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641569258912/hFuoHNzGu.png" alt="carbon (3).png" width="880" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we stored subtract function in the result variable.&lt;/p&gt;

&lt;p&gt;b. Pass function as an argument &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ERNfujDs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641569848196/HvnWeZEE7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ERNfujDs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641569848196/HvnWeZEE7.png" alt="carbon (4).png" width="880" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;anotherFunction = is a &lt;strong&gt;&lt;em&gt;High Order Function&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;subtract =  is a &lt;strong&gt;&lt;em&gt;callback function&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here we passed the &lt;strong&gt;&lt;em&gt;subtract&lt;/em&gt;&lt;/strong&gt; function as an argument to &lt;strong&gt;&lt;em&gt;anotherFunction&lt;/em&gt;&lt;/strong&gt;. &lt;br&gt;
Functions that accept other functions as an argument, or return another function are called &lt;strong&gt;&lt;em&gt;High Order Function&lt;/em&gt;&lt;/strong&gt; and that function which is passed as an argument is called &lt;strong&gt;&lt;em&gt;callback function&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;c. Return another function as a return value&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6mzGFePi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641570488335/zvuYq305n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6mzGFePi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641570488335/zvuYq305n.png" alt="carbon (5).png" width="880" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we are returning &lt;strong&gt;&lt;em&gt;multiply&lt;/em&gt;&lt;/strong&gt; function as a return value to the &lt;strong&gt;&lt;em&gt;calculation&lt;/em&gt;&lt;/strong&gt; function.&lt;/p&gt;

&lt;p&gt;Types of the functions in JavaScript&lt;/p&gt;

&lt;p&gt;(i) Anonymous Functions&lt;/p&gt;

&lt;p&gt;(ii) Immediately Invoked Function Expression (IIFE) &lt;/p&gt;

&lt;p&gt;(iii) Arrow functions&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Anonymous Functions
&lt;/h2&gt;

&lt;p&gt;Anonymous functions are functions without names. The anonymous function has no name between the function keyword and the parentheses (). These functions are defined by declaring a function body to a variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l5AMABA8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641646463469/TvKT-0NB1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l5AMABA8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641646463469/TvKT-0NB1.png" alt="carbon (7).png" width="880" height="429"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Immediately Invoked Function Expression (IIFE)
&lt;/h2&gt;

&lt;p&gt;IIFE are the functions expressions that are invoked just after the declaration of the function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ji_HbbDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641647234919/zZ9zrQEk_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ji_HbbDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641647234919/zZ9zrQEk_.png" alt="carbon (8).png" width="880" height="429"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Arrow Function
&lt;/h2&gt;

&lt;p&gt;Arrow function was provided in the ES6 version of JavaScript. It is the shorter syntax to write the functions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qwGIYcWn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641648198692/DrC9UHZpN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qwGIYcWn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641648198692/DrC9UHZpN.png" alt="carbon.png" width="880" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can avoid using parentheses() if there is only &lt;em&gt;ONE&lt;/em&gt; parameter used in the function. But if there are no parameters used then you &lt;strong&gt;MUST USE&lt;/strong&gt; &lt;em&gt;parentheses()&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GpHOH_oT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641648613848/JvJ8hPMZr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GpHOH_oT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1641648613848/JvJ8hPMZr.png" alt="carbon (1).png" width="880" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also avoid the &lt;strong&gt;&lt;em&gt;curly brackets { }&lt;/em&gt;&lt;/strong&gt; if the function is only of one line.&lt;/p&gt;




&lt;p&gt;Thanks for reading the blog. Do share your valuable feedbacks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Connect on &lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>functional</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Difference b/w for...in &amp; for...of</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Mon, 06 Dec 2021 09:33:26 +0000</pubDate>
      <link>https://dev.to/vanshsh/difference-bw-forin-forof-4of4</link>
      <guid>https://dev.to/vanshsh/difference-bw-forin-forof-4of4</guid>
      <description>

&lt;p&gt;The distinction between the &lt;code&gt;for..in&lt;/code&gt; and &lt;code&gt;for..of&lt;/code&gt; methods of arrays in JavaScript will be discussed in this blog.&lt;/p&gt;

&lt;p&gt;These methods are a simplified form of the actual &lt;code&gt;for&lt;/code&gt; loop, &lt;strong&gt;&lt;em&gt;however they should not be used in place of the standard &lt;code&gt;for&lt;/code&gt; loop.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;for&lt;/code&gt; loop
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for( let i=0; i&amp;lt;length; i++) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the standard &lt;code&gt;for&lt;/code&gt; loop which iterates over the length and returns i . &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;for...in&lt;/code&gt; loop &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EgnRRS82--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638710175661/-B6E9MduD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EgnRRS82--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638710175661/-B6E9MduD.png" alt="carbon.png" width="775" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Synatx:  for( let key in obj) &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;👉 It is for iterating over the "enumerable" properties of an object.&lt;/p&gt;

&lt;p&gt;👉 It gives us the keys/properties of an object.&lt;/p&gt;

&lt;p&gt;👉 It is mostly used with objects.&lt;/p&gt;

&lt;p&gt;👉 It does not have a specific order of execution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;for...of&lt;/code&gt; loop &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4aDdIQJE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638710492266/TLjFztrNq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4aDdIQJE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638710492266/TLjFztrNq.png" alt="carbon (1).png" width="775" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Synatx: for(let value of array)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;👉 It is used to iterate over "iterable".&lt;/p&gt;

&lt;p&gt;👉 It is mostly used with strings and arrays&lt;/p&gt;

&lt;p&gt;👉 It does not work with objects as they are not &lt;br&gt;
      "iterable".&lt;/p&gt;




&lt;p&gt;❤️// 👍&lt;/p&gt;

&lt;p&gt;This topic had always been a source of uncertainty for me, so I decided to write a blog on it in order to learn more about it so that I might help someone else who was in the same boat.&lt;/p&gt;

&lt;p&gt;Do Like and  SHARE your valuable feedback.&lt;/p&gt;

&lt;p&gt;Connect 🔗&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>array</category>
      <category>webdev</category>
    </item>
    <item>
      <title>REST vs. SPREAD</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Sun, 14 Nov 2021 10:23:54 +0000</pubDate>
      <link>https://dev.to/vanshsh/rest-vs-spread-2d9h</link>
      <guid>https://dev.to/vanshsh/rest-vs-spread-2d9h</guid>
      <description>&lt;h3&gt;
  
  
  The &lt;strong&gt;&lt;em&gt;Rest parameter&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;Spread Syntax&lt;/em&gt;&lt;/strong&gt; were added in JavaScript ES6 (ECMAScript 6) despite the fact that their symbols are the same they work differently.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parameters are value passed inside the function definition :&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;function add(paramter){ }&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Arguments are value passed while calling the functions&lt;/p&gt;

&lt;p&gt;add(arguments)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Let's discuss about them using the explanation and examples.
&lt;/h4&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Rest Parameter&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Sometimes while creating the  function we face the situation where the value of number of arguments to be passed are unknown to us. There comes the &lt;strong&gt;&lt;em&gt;Rest Parameter&lt;/em&gt;&lt;/strong&gt; to our rescue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;--- Without Rest parameter ---&amp;gt;

function add(a, b) {
  console.log(a + b);
}

add(5, 6) // 11
add(5, 6, 2, 3) // 11, It will just ignore the rest of the arguments except(2,3) because we have given only 2 parameters

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;--- With Rest Parameter ---&amp;gt;

function add(...args) {
  let sum = 0;
  for (let arg of args) {
    sum += arg;
  }
  return sum;
}

let array = [1, 2, 3, 4, 5, 6, 7, 8, 9]

console.log(add(2, 3)) // 5
console.log(add(2, 3, 6)) // 11
console.log(add(2, 3, 7, 4, 2, 5)) // 23

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Point to Remember&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The rest parameter is always used at the end of the function parameters
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b, ...rest){}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Spread Syntax&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Sometimes we need to add the an array of values as the arguments to the functions because adding each value to the arguments will not be good practice. There comes the &lt;strong&gt;Spread Synatx&lt;/strong&gt; for our rescue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;--- Without Spread Sytax ---&amp;gt;

console.log(Math.max(1,3,4,6,7,9,98,74,56,32,12,36)) // 98
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;---With Spread Syntax ---&amp;gt;

let arr = [1,3,4,6,7,9,98,74,56,32,12,36];

console.log(Math.max(...arr)) // 98 



let arr1 = [1, -2, 3, 4];
let arr2 = [8, 3, -8, 1];

console.log(Math.max(1, ...arr1, 2, ...arr2, 25)); // 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Point to Remember&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Unlike &lt;strong&gt;rest parameter&lt;/strong&gt;, &lt;strong&gt;spread syntax&lt;/strong&gt; can be used anywhere in the function arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Math.max(1, ...arr1, 2, ...arr2, 25));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Difference&lt;/strong&gt;
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rest Parameter&lt;/th&gt;
&lt;th&gt;Spread Syntax&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;When {...} appears in the&lt;br&gt;function definition it is called Rest Parameter&lt;/td&gt;
&lt;td&gt;When {...} appears in the&lt;br&gt;function call it is called Spread Syntax.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;function add(...restParameter){&lt;br&gt;&lt;br&gt;// code&lt;br&gt;  &lt;br&gt; }&lt;/td&gt;
&lt;td&gt;let arr= [1,2,3,4,5,6,7,8,9]&lt;br&gt; &lt;br&gt;add(...spreadSynatx)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;Connect: &lt;br&gt;
&lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://javascript.info/rest-parameters-spread"&gt;Reference&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Operators in JavaScript</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Sat, 09 Oct 2021 06:06:31 +0000</pubDate>
      <link>https://dev.to/vanshsh/operators-in-javascript-4412</link>
      <guid>https://dev.to/vanshsh/operators-in-javascript-4412</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Credit : &lt;a href="https://simplesnippets.tech/operators-in-javascript-programming/"&gt;Tanmay Sankalp&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Operators: Operators are basic mathematical symbols that perform some sort of operation/function on operands.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3 + 5 = 8

3,5 is Operand

+,= is Operator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Topics
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; Basic Operators &lt;code&gt;+, -, *, /, %&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Comparison Operators &lt;code&gt;&amp;gt;, &amp;lt;, &amp;gt;=, ==,===&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Ternary Operator &lt;code&gt;?&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Logical Operators &lt;code&gt;||, &amp;amp;&amp;amp;, !, ??&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Basic Operators&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Addition &lt;code&gt;+&lt;/code&gt;, Multiplication &lt;code&gt;*&lt;/code&gt;, Subtraction &lt;code&gt;-&lt;/code&gt;, Division (quotient) &lt;code&gt;/&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 10;
let b = 5;

console.log(a+b); // Output : 15

console.log(a*b); // Output : 50

console.log(a-b); // Output : 5

console.log(a/b); // Output : 2

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remainder &lt;code&gt;%&lt;/code&gt;, Exponentiation &lt;code&gt;**&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 4;
let b = 2;

console.log(a%b); // Output : 0

console.log(a**b); // Output : 16


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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Special use of &lt;code&gt;+&lt;/code&gt; operator. It is also used for string concatenation. After the introduction of &lt;code&gt;Backticks (&lt;/code&gt;&lt;code&gt;) in the ES6 version.&lt;/code&gt;It is not used that frequently.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  NOTE: &lt;code&gt;+&lt;/code&gt; has a special feature to convert operand to string other operators works only with number
&lt;/h3&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Vansh " + " Sharma") // Output "Vansh Sharma"

console.log('5' + 1) // Output "51"

console.log(2+'2'+'1') //Output "221"

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Comparison Operators&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  These are operators are used to compare two values. Comparison operators always returns result in Boolean form &lt;code&gt;true&lt;/code&gt;( means 'Yes','Correct'), &lt;code&gt;false&lt;/code&gt;(means 'No','Wrong'). JavaScript converts the value to numbers so always use &lt;strong&gt;strict comparison&lt;/strong&gt;.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Greater than &lt;code&gt;&amp;gt;&lt;/code&gt;, Less than &lt;code&gt;&amp;lt;&lt;/code&gt;, Greater than and equal &lt;code&gt;&amp;gt;=&lt;/code&gt;, Less than and equal &lt;code&gt;&amp;lt;&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 &amp;gt; 4); // Output true

console.log(5 &amp;lt; 4); // Output false

console.log(5 &amp;gt;= 4); // Output true

console.log(5 &amp;lt;= 5); // Output true

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Double Equals &lt;code&gt;==&lt;/code&gt; only compares the value, Triple Equals &lt;code&gt;===&lt;/code&gt; compares the value and datatype both, Not Equal &lt;code&gt;!=&lt;/code&gt;/&lt;code&gt;!==&lt;/code&gt; It is always preferred to use the latter.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 == "5") // Output true because it compared 5 with 5

console.log(5 === "5") // Output false because it compared number(5) with string(5)

console.log(5 !== "5") // Output true because it compared number(5) with string(5)



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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;String Comparison&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Sting comparison follows the English dictionary order (Unicode).&lt;/li&gt;
&lt;li&gt;While comparing the small letter with a capital letter. Small letters are always considered greater because of the greater index.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log('Z' &amp;gt; 'A') // true
console.log('l' &amp;gt; 'm') // false
console.log('k' &amp;gt; 'Z') // true

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Point to remember&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;h3&gt;
  
  
  &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt; converts &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt; to 0 and NaN respectively.
&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; are only equal (==) to each other.
&lt;/h3&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(null == undefined) // true
console.log(null === undefined) // false
console.log(null == 0) // false
console.log(null &amp;lt;= 0) // true becasue null gets converted into 0


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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Ternary Operator&lt;/strong&gt; &lt;code&gt;?&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  It is used as an alternative to small &lt;code&gt;if&lt;/code&gt; code.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  NOTE: Do not use as a complete alternative to &lt;code&gt;if&lt;/code&gt; operator, use this only with small &lt;code&gt;if&lt;/code&gt; code expressions.
&lt;/h3&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Syntax:

let result = condition ? value1(if condition is true) : value2(if condition is not true


let a, b;
a = 5;
b = 7;

let finalAnswer =
  a &amp;gt; b ?'a is greater than b' : ' a is less than b';

  console.log(finalAnswer) // a is less than b

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Logical Operators&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;||&lt;/code&gt; (OR)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;h3&gt;
  
  
  It always returns the first truthy value. Don't check after that.
&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;&lt;h3&gt;
  
  
  Converts the operand to boolean to evaluate the result.
&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  If all operands return the &lt;code&gt;false&lt;/code&gt;, returns the last operand.
&lt;/h3&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
console.log(5 || 0); // 5 ( only truthy value)

console.log(0 || null || undefined || 3); // 3 ( only truthy value)

console.log(undefined || 0 || null); // null ( if all are false return the last value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; (AND)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;h3&gt;
  
  
  It always returns the first falsy value. Don't check after that.
&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;&lt;h3&gt;
  
  
  Converts the operand to boolean to evaluate the result.
&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  If all operands return the &lt;code&gt;true&lt;/code&gt;, returns the last operand.
&lt;/h3&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 &amp;amp;&amp;amp; 0); // 0 (only falsy value)

console.log(1 &amp;amp;&amp;amp; null &amp;amp;&amp;amp; 5); // null (only falsy value)

console.log(5 &amp;amp;&amp;amp; true &amp;amp;&amp;amp; 3); // 3 (if all are true returns the last value)


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

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;!&lt;/code&gt; (NOT)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;h3&gt;
  
  
  Converts the operand to boolean type to evaluate the result.
&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Returns the inverse value.
&lt;/h3&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(!0) // true (because inverse of 0( false) is true)

console.log(!5) // false (because inverse of 5( true) is false)

console.log(!" ") // false (because " " is not empty string so inverse is false)

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;??&lt;/code&gt; Nullish coalescing operator
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It returns the first defined value whereas &lt;code&gt;||&lt;/code&gt; returns the first truthy value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;0 for || is falsy on the other hand 0 for the ?? is defined value.&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;console.log(null ?? undefined ?? 1) // 1 returns the defined value

console.log(0 ?? 1) // 0 because ?? consider 0 as defined value

console.log(0 || 1) // 1 because || consider 0 as falsy value


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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Points to remember&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("" || 5) // 5 (because empty string is 0 (falsy))

console.log(" " || 5) // " " here output is blank space even space is consider as non-empty

console.log( null || 2 &amp;amp;&amp;amp; 3 || 4 ) // 3 because precedence of &amp;amp;&amp;amp; is higher than that of || )


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

&lt;/div&gt;






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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://javascript.info/operators"&gt;Basic Operators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/comparison"&gt;Comparison Operators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/ifelse"&gt;Ternary Operators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/logical-operators"&gt;Logical Operators&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.info/nullish-coalescing-operator"&gt;Nullish coalescing operator &lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>Block Element Modifier</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Mon, 04 Oct 2021 12:35:48 +0000</pubDate>
      <link>https://dev.to/vanshsh/block-element-modifier-4h0i</link>
      <guid>https://dev.to/vanshsh/block-element-modifier-4h0i</guid>
      <description>&lt;blockquote&gt;
&lt;h2&gt;
  
  
  It is popular naming convention for &lt;strong&gt;&lt;em&gt;Classes&lt;/em&gt;&lt;/strong&gt; in &lt;strong&gt;HTML&lt;/strong&gt; and &lt;strong&gt;CSS&lt;/strong&gt;. It was invented at Yandex to develop sites that should be launched fast and supported for a long time. It helps to create extendable and reusable interface components.
&lt;/h2&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Block
&lt;/h2&gt;

&lt;h3&gt;
  
  
  It is an independent component in HTML that has its own meaning and can be reused. It is more of like a &lt;em&gt;parent element&lt;/em&gt;.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Examples: &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; etc.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;header class="header"&amp;gt;

&amp;lt;nav class="nav"&amp;gt;&amp;lt;/nav&amp;gt;

&amp;lt;/header&amp;gt;

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  Element
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Elements are the child element of the &lt;strong&gt;Block&lt;/strong&gt; component. It is mostly the text part inside the block. &lt;strong&gt;Block and Elements are seperated by 2 double underscores &lt;code&gt;(block__element)&lt;/code&gt;&lt;/strong&gt;.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Examples: &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; etc.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;header class="header"&amp;gt;

&amp;lt;h1 class="header__title"&amp;gt; Introduction &amp;lt;/h1&amp;gt;

&amp;lt;/header&amp;gt;

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  Modifier
&lt;/h2&gt;

&lt;h3&gt;
  
  
  As the name suggests it &lt;strong&gt;&lt;em&gt;modify&lt;/em&gt;&lt;/strong&gt; the appearance, state, behaviour of elements. &lt;strong&gt;Elements and Modifiers are seperated by single undersocre (elements_modifiers)&lt;/strong&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Examples: &lt;code&gt;&amp;lt;disabled&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;color&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;active&amp;gt;&lt;/code&gt; etc.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;form class="form"&amp;gt;

&amp;lt;input type="text" class="form__name_disabled" disabled&amp;gt;

&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;NOTE: Some places you will find elements and modifiers are separated using a single underscore (element--modifiers).&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Rules &lt;code&gt;&amp;lt;block-name__element-name_modifier-name&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Names are written in lowercase Latin letters.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  2. Words are seperated by a hyphen (search-form).
&lt;/h3&gt;

&lt;h3&gt;
  
  
  3. The &lt;strong&gt;element&lt;/strong&gt; name is seperated from the &lt;strong&gt;block&lt;/strong&gt; name by a double underscore (header__title).
&lt;/h3&gt;

&lt;h3&gt;
  
  
  4. The &lt;strong&gt;element&lt;/strong&gt; name is seperated from the &lt;strong&gt;modifier&lt;/strong&gt; name by a single underscore (form__input_disabled).
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  A double hyphen inside a comment (--) may cause an error during validation of an HTML document. So it is mostly avoided.
&lt;/h3&gt;
&lt;/blockquote&gt;




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

&lt;h3&gt;
  
  
  &lt;a href="https://en.bem.info/methodology/"&gt;BEM Methodology&lt;/a&gt;
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Contact
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Semantic Elements in HTML</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Thu, 23 Sep 2021 16:22:42 +0000</pubDate>
      <link>https://dev.to/vanshsh/semantic-elements-in-html-34jc</link>
      <guid>https://dev.to/vanshsh/semantic-elements-in-html-34jc</guid>
      <description>&lt;h1&gt;Semantic Elements in HTML&lt;/h1&gt;
 

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  According to Wikipedia &lt;a href="https://en.wikipedia.org/wiki/Semantics"&gt;Semantic&lt;/a&gt; means "Semantics is the study of meaning, reference, or truth"
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  In HTML, we can say that &lt;strong&gt;Semantic Elements are those elements that describe the use of the element from their names.&lt;/strong&gt;
&lt;/h3&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4KSsgOh6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/E2iZoBBVkAA9Xhw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4KSsgOh6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/E2iZoBBVkAA9Xhw.jpg" alt="Semantic Elements"&gt;&lt;/a&gt;&lt;br&gt;
Credit: &lt;a href="https://twitter.com/eyeshreya"&gt;Shreya&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  ▶️  Examples:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Semantic Elements :
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;time&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;details&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-Semantic Elements :
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ▶️ Application:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;: It is used to give a heading to your website.
&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;header&amp;gt;

   &amp;lt;h1&amp;gt; Introduction to HTML &amp;lt;/h1&amp;gt;

 &amp;lt;/header&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;: It is used to add a navigation bar to your website to provide links for different pages.
&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;nav&amp;gt;

     &amp;lt;a href=""&amp;gt; About HTML &amp;lt;/a&amp;gt;
     &amp;lt;a href=""&amp;gt; Elements &amp;lt;/a&amp;gt;
     &amp;lt;a href=""&amp;gt; Examples&amp;lt;/a&amp;gt;
     &amp;lt;a href=""&amp;gt; Quiz&amp;lt;/a&amp;gt;

    &amp;lt;/nav&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;: It is used to specify the main content of the page.
&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;main&amp;gt;

  &amp;lt;p&amp;gt;
   HTML is the standard markup language for Web pages. 

   With HTML you can create your own Website.
  &amp;lt;/p&amp;gt;

  &amp;lt;/main&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;: It can be used to group the different sections of the web page.
&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;section&amp;gt;

  &amp;lt;h2&amp;gt; About HTML &amp;lt;/h2&amp;gt;

&amp;lt;/section&amp;gt;

&amp;lt;section&amp;gt;

  &amp;lt;h2&amp;gt; Elements &amp;lt;/h2&amp;gt;

&amp;lt;/section&amp;gt;

&amp;lt;section&amp;gt;

  &amp;lt;h2&amp;gt; Examples &amp;lt;/h2&amp;gt;

&amp;lt;/section&amp;gt;

&amp;lt;section&amp;gt;

  &amp;lt;h2&amp;gt; Quiz &amp;lt;/h2&amp;gt;

&amp;lt;/section&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;: It is mostly used to display the contents on the side of the main page related to the content of the web page.
&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;aside&amp;gt;

&amp;lt;h3&amp;gt; Fact about HTML &amp;lt;/h3&amp;gt;

&amp;lt;p&amp;gt; HTML is a programming language or not is a contentious topic among the programmers. &amp;lt;/p&amp;gt;

&amp;lt;/aside&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;: As its name suggests it is used at the bottom of the page which mostly contains the &lt;em&gt;contact details&lt;/em&gt; or &lt;em&gt;query form&lt;/em&gt;.
&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;footer&amp;gt;

&amp;lt;h3&amp;gt; Contact information &amp;lt;/h3&amp;gt;

&amp;lt;a href=""&amp;gt; Twitter &amp;lt;/a&amp;gt;
&amp;lt;a href=""&amp;gt; LinkedIn &amp;lt;/a&amp;gt;
&amp;lt;a href=""&amp;gt; GitHub &amp;lt;/a&amp;gt;

&amp;lt;footer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ▶️ Benefits of Semantic Elements:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Screen readers can help visually impaired users to navigate a page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Helps in improving the SEO ranking of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Makes refactoring of the code easier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Helps the developer to understand the type of data elements holds&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ▶️ Semantic elements table:
&lt;/h2&gt;

&lt;p&gt;There are many semantic elements in the HTML some of them are mentioned here.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Elements&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Define independent, self-contained content&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines content aside from the page content&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;details&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines additional details&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;figcaption&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines the caption for the figure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;figure&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Includes the content like image, diagrams, photos&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines the footer section of the page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines the header section of the page.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines the main content of the page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains the navigation bar of the page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines the different section of the pages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;summary&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines a visible heading for a details element&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  📚 Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/html/html5_semantic_elements.asp"&gt;w3schools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Semantics#semantics_in_html"&gt;MDN docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This blog is part of my contribution to GirlScript Winter of Contributing more contributions to come.&lt;/p&gt;

&lt;p&gt;Meet you in the next blog until then &lt;strong&gt;Keep Learning, Keep Growing&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Connect:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>7 Ways to Write Good commit message</title>
      <dc:creator>Vansh Sharma</dc:creator>
      <pubDate>Fri, 13 Aug 2021 09:08:13 +0000</pubDate>
      <link>https://dev.to/vanshsh/7-ways-to-write-good-commit-message-5a5d</link>
      <guid>https://dev.to/vanshsh/7-ways-to-write-good-commit-message-5a5d</guid>
      <description>&lt;h2&gt;
  
  
  What is a commit message?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Brief description of the changes you made to the codebase. So that other members of the team can understand all changes you made to the codebase.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why is it necessary to write a &lt;strong&gt;good&lt;/strong&gt; commit message?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It is a good habit to write a good commit message because people come and go but code remains there. So you should commit in such a way that future members and the member of other teams can understand What all changes you have made?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's see an example of the &lt;strong&gt;GOOD &amp;amp; BAD&lt;/strong&gt; Commit message.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example1 &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uH6EMFIe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628782797846/FzGBjcRak.png" alt="carbon.png"&gt;
&lt;/li&gt;
&lt;li&gt;Example 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qVQ2oPWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628842791309/2q3lVkg5M.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qVQ2oPWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628842791309/2q3lVkg5M.png" alt="carbon (1).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Points to remember while writing &lt;strong&gt;&lt;em&gt;Commit message&lt;/em&gt;&lt;/strong&gt; :
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Divide the commit message into 2 parts: &lt;strong&gt;subject&lt;/strong&gt; and &lt;strong&gt;body&lt;/strong&gt;.&lt;br&gt;
In the above &lt;em&gt;Example 2&lt;/em&gt; &lt;strong&gt;1st message is subject part&lt;/strong&gt; and &lt;strong&gt;2nd message is body part&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Mention the type of commit you are making in &lt;strong&gt;Subject part&lt;/strong&gt; such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Feat: For any new feature&lt;/li&gt;
&lt;li&gt; Fix: If you fix any bug&lt;/li&gt;
&lt;li&gt; Docs: Changes in documentation &lt;/li&gt;
&lt;li&gt;Style: Any changes in style like color, design etc.&lt;/li&gt;
&lt;li&gt;Refactor: When you refactor the code&lt;/li&gt;
&lt;li&gt;Test: Anything related to testing&lt;/li&gt;
&lt;li&gt;Chore: Regular code maintenance&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Limit the &lt;strong&gt;subject&lt;/strong&gt; line to 50 characters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don't end the &lt;strong&gt;subject&lt;/strong&gt; line with a period (.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;strong&gt;&lt;em&gt;Imperative mood&lt;/em&gt;&lt;/strong&gt; in &lt;strong&gt;subject&lt;/strong&gt; line &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Imperative mood is like giving orders. Like:  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Fix the bug&lt;/li&gt;
&lt;li&gt;Change background color&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wrap the &lt;strong&gt;body&lt;/strong&gt; part at 72 characters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Capitalize the &lt;strong&gt;subject&lt;/strong&gt; line and each &lt;strong&gt;paragraph&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's all for this blog. We will meet in the next blog until then &lt;strong&gt;&lt;em&gt;Keep learning, Keep growing&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Connect with me : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://twitter.com/Vanshsh2701"&gt;Twitter&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.linkedin.com/in/vanshsharma27/"&gt;LinkedIn&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reference :&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/"&gt;FreeCodeCamp&lt;/a&gt;  &lt;br&gt;  &lt;a href="https://neog.camp/guide/lesson-two"&gt;Neogcamp&lt;/a&gt; &lt;/p&gt;

</description>
      <category>github</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
