<?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>Forem: Suresh Pal Pranta</title>
    <description>The latest articles on Forem by Suresh Pal Pranta (@pranta07).</description>
    <link>https://forem.com/pranta07</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%2F800117%2F428febd2-d36e-49c5-b2c3-4ed853c420f2.png</url>
      <title>Forem: Suresh Pal Pranta</title>
      <link>https://forem.com/pranta07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pranta07"/>
    <language>en</language>
    <item>
      <title>TypeScript Basics</title>
      <dc:creator>Suresh Pal Pranta</dc:creator>
      <pubDate>Fri, 15 Apr 2022 10:38:41 +0000</pubDate>
      <link>https://forem.com/pranta07/typescript-basics-3g9i</link>
      <guid>https://forem.com/pranta07/typescript-basics-3g9i</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;TypeScript vs JavaScript&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;TypeScript is a superset of JavaScript. That means TypeScript has some extra features to JavaScript. In JavaScript, we don't need to define the type but in TypeScript, we have strictly followed the type. As a result, the chance of bugs will be lower.&lt;/p&gt;

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

&lt;p&gt;Some common types are - &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;,  &lt;code&gt;undefined&lt;/code&gt;,  &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;unknown&lt;/code&gt;, &lt;code&gt;any&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Number&lt;/strong&gt;&lt;br&gt;
In TypeScript, a variable that will store a decimal number the type of the variable should be defined as type &lt;code&gt;number&lt;/code&gt;. While big integer gets the type &lt;code&gt;bigint&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;const total: number = 1000;
const discount: number = 1000*0.1;
const max: bigint = 10n ** 9n;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt;&lt;br&gt;
In TypeScript a variable that will store textual data, the type of the variable should be defined as type &lt;code&gt;string&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;const name: string = "Pranta";
const position: string = "Frontend Developer";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt;&lt;br&gt;
This is one of the basic types which contains &lt;code&gt;boolean&lt;/code&gt; value &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&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;const loading: boolean = true|false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Array&lt;/strong&gt;&lt;br&gt;
We can define a type of array in three ways. The First two ways have explicitly defined the types. The third way simplifies the task by using an &lt;code&gt;interface&lt;/code&gt; or &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;First way -
const numbers: number[] = [1, 2, 3]
const products: string[] = ["bag", "laptop", "mobile"]
&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;Second way -
const numbers: Array&amp;lt;number&amp;gt; = [1, 2, 3]
const products: Array&amp;lt;string&amp;gt; = ["bag", "laptop", "mobile"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we have an array of objects then we can use the &lt;code&gt;type&lt;/code&gt; keyword or define an &lt;code&gt;interface&lt;/code&gt; specifying the type of all properties in an object. Best way to use &lt;code&gt;interface&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;const IProducts {
   name: string;
   price: number;
}
const products: IProducts[] =[{ name: "Mobile", price: 10000}, { name: "Mobile", price: 10000 }];

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Any&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;any&lt;/code&gt; type is rarely used. It helps to work with the existing JavaScript code. When all the data types are not known then we can assume it as &lt;code&gt;any&lt;/code&gt; type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const looselyTypedVariable: any = {};
console.log(looselyTypedVariable.name); //don't give any error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, there are some drawbacks to using &lt;code&gt;any&lt;/code&gt; type. With &lt;code&gt;any&lt;/code&gt; type TypeScript will not give any error whether we are accessing a property that doesn't exist in that object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const strictlyTypedVariable: {name: string} = {name:"Pranta"};
console.log(strictlyTypedVariable.age); //show error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without using &lt;code&gt;any&lt;/code&gt; we can use &lt;code&gt;unknown&lt;/code&gt; type as well which is more meaningful. We should try to avoid using &lt;code&gt;any&lt;/code&gt; when not necessary as it doesn't ensure the type safety.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>MongoDB with Node.js, CRUD Operation</title>
      <dc:creator>Suresh Pal Pranta</dc:creator>
      <pubDate>Fri, 21 Jan 2022 11:04:37 +0000</pubDate>
      <link>https://forem.com/pranta07/mongodb-with-nodejs-crud-operation-2d99</link>
      <guid>https://forem.com/pranta07/mongodb-with-nodejs-crud-operation-2d99</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;MongoDB&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;MongoDB is a no-SQL database. It represents data as JSON documents. It maintains some collections where data are stored as documents. It is much more flexible than an SQL database since we can store documents of different formats in the same collection. One more advantage is that we can use JavaScript as our query language.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Node.js&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Node.js is a non-blocking JavaScript runtime environment. Client-side JavaScript codes are executed in the browser. Node.js is used to run JavaScript code outside the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Node.js vs JavaScript&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;JavaScript is a programming language that is used for front-end development while Node.js is used for server-side development. JavaScript codes are executed in the browser normally. With the help of Node.js, we can run JS code outside the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Connecting MongoDB with node.js server&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to MongoDB atlas and create an account.&lt;/li&gt;
&lt;li&gt;Create a cluster.&lt;/li&gt;
&lt;li&gt;Go to database access and create a user.&lt;/li&gt;
&lt;li&gt;Allow network access.&lt;/li&gt;
&lt;li&gt;Click on connect and then connect your application.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Replace the username and password carefully in the connection string of your cluster with valid &lt;code&gt;username&lt;/code&gt; and &lt;code&gt;password&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;const { MongoClient } = require('mongodb');
const uri = "mongodb+srv://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@cluster0.yxq3j.mongodb.net/myFirstDatabase?retryWrites=true&amp;amp;w=majority";
&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;const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
client.connect(err =&amp;gt; {
  const productsCollection = client.db("testDB").collection("products");
  console.log(“Database connected successfully!”);  
  // client.close();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Create or Insert Operation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We can insert a single document or multiple documents into a collection. To insert a single document we need to use the &lt;code&gt;insertOne()&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;const product = {
      category: "Shirt",
      price: 200
}
const result = productsCollection.insertOne(product);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to insert many documents then we need to use the &lt;code&gt;insertMany()&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;const docs = [
      { name: "apple", price: 30 },
      { name: "orange", price: 50 }
];
const result = foods.insertMany(docs);

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Read or Find Operation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To find a document from the database we need to use &lt;code&gt;findOne()&lt;/code&gt; method and we can pass query and options as parameter of this method to find our desired document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Query for a mobile that has the title 'Redmi Note 4'
const query = { title: "Redmi Note 4" };
const mobile = movies.findOne(query);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To find multiple documents from a collections we need to use &lt;code&gt;find()&lt;/code&gt; method. This method will return a cursor and we can apply cursor methods &lt;code&gt;next()&lt;/code&gt;, &lt;code&gt;toArray()&lt;/code&gt;, &lt;code&gt;forEach()&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;const cursor = products.find({});
const products = cursor.toArray();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Update Operation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To update  a single document we need to use &lt;code&gt;updateOne()&lt;/code&gt; method. In this method we can pass three parameters &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;updateDoc&lt;/code&gt; and &lt;code&gt;options&lt;/code&gt; which is optional.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// create a filter for a product to update
const filter = { name: "Redmi Note 4" };
// create a new document if no documents match the filter
const options = { upsert: true };
// updating a document that sets the price of the mobile
const updateDoc = {
      $set: {
        price: 20000
      },
};
const result = movies.updateOne(filter, updateDoc, options);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To update multiple documents we need to use &lt;code&gt;updateMany()&lt;/code&gt; method.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Delete Operation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We can delete a single document or multiple documents if we want. To delete a single document we need to use &lt;code&gt;deleteOne()&lt;/code&gt; method and passing a query parameter to this method we will specify which documents we want to delete.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const query = { title: "Redmi9" };
const result = mobileCollection.deleteOne(query);

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

&lt;/div&gt;



&lt;p&gt;To delete multiple documents we need to use &lt;code&gt;deleteMany()&lt;/code&gt; method.&lt;/p&gt;

</description>
      <category>blogging</category>
    </item>
    <item>
      <title>React.js Core Concepts</title>
      <dc:creator>Suresh Pal Pranta</dc:creator>
      <pubDate>Thu, 20 Jan 2022 19:16:28 +0000</pubDate>
      <link>https://forem.com/pranta07/reactjs-core-concepts-51ha</link>
      <guid>https://forem.com/pranta07/reactjs-core-concepts-51ha</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;React.js and its pros &amp;amp; cons&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;React is a declarative, component-based JavaScript library for building user interfaces.&lt;br&gt;
Pros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use virtual DOM to effectively render user interfaces.&lt;/li&gt;
&lt;li&gt;Supports component-based design which is reusable and easy to manage.&lt;/li&gt;
&lt;li&gt;Single page application means rendering different components on the same page efficiently without any reload. Which makes a better user experience. &lt;/li&gt;
&lt;li&gt;The HTML-like syntax is easy to learn and use.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Continuously updated features which is a bit challenging for developers to cope up with new documentation. &lt;/li&gt;
&lt;li&gt;Still contains class-based components example in documentation instead of functional components.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;JSX&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;JSX means JavaScript XML which allows HTML-like syntax with JavaScript in react. Using JSX we can create dynamic content in our react application easily. Without JSX the code is a bit lengthy and complex while using JSX the code is simple and easy to understand. Babel is used by React to convert the JSX to React elements.&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 Blogs = () =&amp;gt; {
    return (
        &amp;lt;div&amp;gt;
            &amp;lt;img
                src="https://i.ibb.co/2SfqRWr/maxresdefault.jpg"
                alt=""
                width="100%"
            /&amp;gt;
        &amp;lt;/div&amp;gt;
    );
};

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

&lt;/div&gt;



&lt;p&gt;In the above code snippet inside the return statement it looks like html syntax actually it is JSX notation which makes us easier to understand what our code structure will looks like.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Virtual DOM&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It is a virtual representation or copy of the real DOM object. Whenever anything changes in our document react will create a new virtual DOM and compare it with the previous DOM, find out the change between these two DOMs using diff algorithm and finally update the specific changes into the real DOM without updating the entire dom. This makes DOM-manipulation more effective without updating the entire DOM whenever a small part of the DOM is changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Props and State&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Props are mainly used for passing dynamic data from parent component to child components while the state is a variable that is used to store information about a specific component and that can be changed dynamically. Props are read-only and immutable which means we can not change props. When the state changes re-render will happen dynamically.&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 Blogs = () =&amp;gt; {
    const blogs = ["blog1","blog2","blog3","blog4","blog5",]
    return (
        blogs.map(blogTitle =&amp;gt; &amp;lt;Blog title={blogTitle}&amp;gt;&amp;lt;/Blog&amp;gt;)
    );
};
export default Blogs;
&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;import React from "react";
const Blog = (props) =&amp;gt; {
    const {title} = props;
    return (
        &amp;lt;h1&amp;gt;{title}&amp;lt;/h1&amp;gt;
    );
};
export default Blog;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Lifting State Up&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We cannot pass states from child to parent component. React follows a top-down approach for passing state between many level components. When a parent component needs the state we need to lift the state up to the parent component and pass this as a prop to the child components. This is called &lt;code&gt;lifting state up&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Props Drilling and Context API&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When data are passed from component to component by props on a deeper level this is called props drilling.&lt;br&gt;
The best way to pass data 4-5 layers down is using context API. Context API is used to pass multiple data all over the document which is simple and easy to use. Whenever we need to share multiple data between many level components we can use context API to provide those data to the whole document. &lt;br&gt;
First, we have to create a context then we have to wrap our document between context Providers where we should specify the value we want to pass. We can get the value we provide from anywhere with the help of &lt;code&gt;useContext&lt;/code&gt; hook.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Custom hook&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hooks are mainly a JavaScript function that can perform some task and returns the results we need. Building our own custom hook will help us to simplify our code which is easy to understand. For creating a custom hook we have to create a JavaScript function and export it so that it can be imported from any component we want and use it.&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";

const useProducts = () =&amp;gt; {
    const [products, setProducts] = useState([]);
    fetch(url)
    .then(res =&amp;gt; res.json())
    .then(data =&amp;gt; setProducts(data));
    return { products };
};

export default useProducts;

&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;const products = useProducts();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Performance Optimization&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To optimize a react.js app we should try to divide different parts of our application into smaller chunks, use react fragments to avoid unnecessary elements for wrapping, try to avoid using an index as a key for the map, using useMemo, pure component, use of spread operator, passing object as props, etc. which will prevent unnecessary component re-render in React.js.&lt;/p&gt;

</description>
      <category>blogging</category>
    </item>
    <item>
      <title>JavaScript Concepts</title>
      <dc:creator>Suresh Pal Pranta</dc:creator>
      <pubDate>Thu, 20 Jan 2022 15:21:01 +0000</pubDate>
      <link>https://forem.com/pranta07/javascript-concepts-48cg</link>
      <guid>https://forem.com/pranta07/javascript-concepts-48cg</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;How does JavaScript work&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;JavaScript is a synchronous and single-threaded language. JavaScript maintains a concurrency model which is consists of a call stack, a heap, a callback queue, and an event loop. When any asynchronous function comes in call stack it will move this piece of code to the web Api’s and continue to the next line. When the asynchronous function completed its task it will be forwarded to the call back queue. Finally when the call stack is empty event loop works in FIFO style and takes one by one from the queue. That is how the overall process works.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Truthy and Falsy values in JavaScript&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In JavaScript, truthy values are true, any number except zero, non-empty string, array, objects, etc.&lt;br&gt;
Falsy values are false, 0, empty string, undefined, null, and NaN.&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%2F19gkktfvrwacu909j76a.JPG" 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%2F19gkktfvrwacu909j76a.JPG" alt="Truthy and Falsy Values"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can say that anything that is not falsy will be truthy in JavaScript.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Implicit Type Coercion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;JavaScript attempts to coerce or convert an unexpected value type to the expected type; it is called implicit type coercion. When two operands of different data types need to compare or perform any operation then JavaScript tries to convert two different types of value to the same type and then compares or performs the operation. &lt;br&gt;
For example, if we perform addition between a string and a number eg. &lt;code&gt;“Pranta” + 123&lt;/code&gt; then the output in the console we see &lt;code&gt;“Pranta123”&lt;/code&gt;. This is because without indicating any error JS compiler change the data types of the number &lt;code&gt;123&lt;/code&gt; to string like &lt;code&gt;“123”&lt;/code&gt; and then perform the addition &lt;code&gt;“Pranta” + “123” = “Pranta123”&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;console.log("Pranta"+123);
Output: "Pranta123"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Double equal &lt;code&gt;==&lt;/code&gt; vs Triple equal &lt;code&gt;===&lt;/code&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;==&lt;/code&gt; is called a loose equality operator because it compares only values of two operands. while &lt;code&gt;===&lt;/code&gt; is called a strict equality operator because it compares both values and types of the variable. Most interesting part is &lt;code&gt;==&lt;/code&gt; trigger implicit coercion but &lt;code&gt;===&lt;/code&gt; does not.&lt;br&gt;
For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“12” == 12 ? “Yes” : “No”; 
Output: Yes. Since it only checks values, not types.
“12” === 12 ? “Yes” : “No”; 
Output: No. Since both values and types are not the same.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Scope in JavaScript&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Scope means the accessibility of variables and functions in different parts of our source code. There are 3 different types of scope in JavaScript. Global scope, local or function scope, and block scope.&lt;br&gt;
Global scope means that we can access it from anywhere in our code. Local or function scope is when we declare any variable inside a function they are in functional scope or local scope. We cannot access those variables outside of the function. Block scope means that variables declared within curly braces are block-scoped we cannot access them outside of the block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var price=100;
function total(){
   var total=price + (price/100)*10;
   console.log(total);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code &lt;code&gt;price&lt;/code&gt; is a global variable and it is globally scoped we can access it from anywhere. But &lt;code&gt;total&lt;/code&gt; is a local variable and it is locally scoped so that we can not access it from outside of the function &lt;code&gt;total()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;API&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;API or application programming interface is a method of communicating between two applications. API takes a request from the client-side and tells the system what we want to do. After the task is completed it will give a response back.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;GET vs POST&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;GET and POST are the two most common HTTP methods. Using the GET method we want to get data from the server specifying the resource path. POST method is used when we want to send any data to the server to insert it into the database. Data is sent inside the body of the request. Then server finds the data and performs the specified task. GET requests can be cached, bookmarked, and remain in browser history while POST requests are not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//GET method
fetch(url)
.then(res =&amp;gt; res.json())
.then(data =&amp;gt; console.log(data));

//POST method
fetch(url,{
   method: "POST",
   headers:{
     "content-type": "application/json",
   }
   body: JSON.stringify(data);
})
.then(res =&amp;gt; res.json())
.then(result =&amp;gt; console.log(result));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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