<?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: Basharath</title>
    <description>The latest articles on DEV Community by Basharath (@basharath).</description>
    <link>https://dev.to/basharath</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%2F547002%2Fd066d639-14c3-4f47-8a8a-15b65774eaf9.jpg</url>
      <title>DEV Community: Basharath</title>
      <link>https://dev.to/basharath</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/basharath"/>
    <language>en</language>
    <item>
      <title>How to handle forms on static sites for FREE?</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Wed, 08 Jun 2022 05:49:47 +0000</pubDate>
      <link>https://dev.to/basharath/how-to-handle-forms-on-static-sites-for-free-30c8</link>
      <guid>https://dev.to/basharath/how-to-handle-forms-on-static-sites-for-free-30c8</guid>
      <description>&lt;p&gt;In the early days of the internet, the information on the web consisted of just static pages. When it became interactive people started generating web pages on the server, making them more dynamic in nature. &lt;/p&gt;

&lt;p&gt;With the advent of new technologies and site generators, a new philosophy of serving web pages is making us think about static pages again. &lt;/p&gt;

&lt;p&gt;This new philosophy or architecture is called JAMstack which stands for JavaScript, APIs and Markdown stack.&lt;/p&gt;

&lt;p&gt;The whole idea of JAMstack is to serve websites as static pages, giving dynamic nature using JavaScript, and exchange data through APIs. &lt;/p&gt;

&lt;p&gt;As a result, it makes the developer experience simpler, improves performance with greater scalability, and reduces the cost of maintenance. &lt;/p&gt;

&lt;p&gt;There are many static site generators available these days viz., NextJS, Hugo, Gatsby, etc. &lt;/p&gt;

&lt;p&gt;With the help of third-party tools or services, these static sites can be made more dynamic. &lt;/p&gt;

&lt;p&gt;Creating and maintaining static sites is inexpensive but adding dynamic features is where one has to spend on third-party tools.&lt;/p&gt;

&lt;p&gt;One essential service which almost every website needs is a contact form and handling contact forms on static sites can be done through third-party services as we don't maintain a full-fledged server to handle forms on static sites.&lt;/p&gt;

&lt;p&gt;Some of the static site form handling services are FormSpree, FormKeep, GetForm etc. These third-party services come at a price and free tier services have limitations in data and the number of submissions. &lt;/p&gt;

&lt;p&gt;But here is a solution that helps you to handle forms on static sites without the need for these third-party tools. &lt;/p&gt;

&lt;p&gt;It is called FormEasy which is a FREE and open-source apps script library that helps you to receive forms on static sites with full control of your data.&lt;/p&gt;

&lt;p&gt;Form spree is a quite popular service for handling forms on static websites and &lt;a href="https://devapt.com/formeasy"&gt;FormEasy&lt;/a&gt; can be the best formspree alternative with all customizations you want.&lt;/p&gt;

&lt;p&gt;Let's see how to set up this FormEasy apps script library to handle static site forms.&lt;/p&gt;

&lt;h2&gt;
  
  
  FormEasy setup
&lt;/h2&gt;

&lt;p&gt;In a few simple steps, forms on static sites can be handled using FormEasy library. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty Google sheets file&lt;/li&gt;
&lt;li&gt;Open the Apps Script file connected to it&lt;/li&gt;
&lt;li&gt;Add the FormEasy library using ScriptID&lt;/li&gt;
&lt;li&gt;Add doPost apps script function&lt;/li&gt;
&lt;li&gt;Deploy the apps script code and get the Web app URL to make POST requests&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Create an empty Google sheets file
&lt;/h3&gt;

&lt;p&gt;Visit this &lt;a href="https://docs.google.com/spreadsheets/u/0/"&gt;link&lt;/a&gt; to create a new blank Google sheets file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LzPuxcJc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgr4nj5h9esbembcx365.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LzPuxcJc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgr4nj5h9esbembcx365.png" alt="Open empty Google sheets file" width="880" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Open the Apps Script file
&lt;/h3&gt;

&lt;p&gt;After creating an empty Google sheet file(you can rename the file if you want to), go to &lt;em&gt;&lt;strong&gt;Extensions&lt;/strong&gt;&lt;/em&gt; in the menu bar and click &lt;em&gt;&lt;strong&gt;Apps Script&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It opens up an apps script file connected with the Google sheet. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZiKWrfZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cg3ql6e1rnw59rlp0wxk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZiKWrfZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cg3ql6e1rnw59rlp0wxk.png" alt="Open apps script file" width="880" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Add the FormEasy library
&lt;/h3&gt;

&lt;p&gt;In the left bar of apps script file click &lt;code&gt;+&lt;/code&gt; button beside &lt;strong&gt;Libraries&lt;/strong&gt; and add the below Script ID and click &lt;strong&gt;&lt;em&gt;Look up&lt;/em&gt;&lt;/strong&gt; button.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ScriptID: 1CAyzGbXdwMlko81SbJAjRp7ewxhyGKhDipDK4v8ZvlpYqrMAAzbFNccL&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gVyzIQQa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhz7fgitgy81xh3umt23.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gVyzIQQa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhz7fgitgy81xh3umt23.png" alt="Add FormEasy library" width="880" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see two options &lt;em&gt;Version&lt;/em&gt; and &lt;em&gt;Identifier&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Select the latest version to reflect the latest changes made to the library if any or you can select the specific version as per the features you want.&lt;/p&gt;

&lt;p&gt;For the identifier, the default name is &lt;em&gt;FormEasy&lt;/em&gt; it is the name of the object used to call methods in the library. You can change it if you want but keeping it as it is can help you use the ready code snippets related to FormEasy.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Add doPost function
&lt;/h3&gt;

&lt;p&gt;Clear the default functions if any in the default apps script file Code.gs.&lt;/p&gt;

&lt;p&gt;Create a function named &lt;code&gt;doPost&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;doPost&lt;/code&gt; function name is the default name of the function that runs whenever a POST request is made to the script.&lt;/p&gt;

&lt;p&gt;Next set the email if you want to get notified whenever any form gets submitted using &lt;code&gt;setEmail&lt;/code&gt; method on FormEasy object. (FormEasy is the default identifier if you do not make any changes to the identifier while adding the FormEasy library)&lt;/p&gt;

&lt;p&gt;Setting email is optional, the data gets logged in the Google sheet and you will not be notified through email if you do not set the email.&lt;/p&gt;

&lt;p&gt;You need to return &lt;code&gt;action&lt;/code&gt; method on FormEasy object with the &lt;code&gt;req&lt;/code&gt; argument from the doPost function and this is the only mandatory method to use and all other methods on FormEasy are optional. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QpTPkGLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pytlwxr3tj7vnpu2g7u4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QpTPkGLW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pytlwxr3tj7vnpu2g7u4.png" alt="doPost function FormEasy" width="880" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the available methods on FormEasy library are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;setShee&lt;/strong&gt;t - To select the specific sheet for saving the data(Default is active sheet)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;setEmail&lt;/strong&gt; - To set the email for receiving notification&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;setSubject&lt;/strong&gt; - To set the subject of the email&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;setFormHeading&lt;/strong&gt; - To set the heading(inside email)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;setFields&lt;/strong&gt; - To set the fields of the form(Lower case letters, also the keys of the JSON object)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;action&lt;/strong&gt; - To return the response after submitting the form(Mandatory to return)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above all are optional methods except the action.&lt;/p&gt;

&lt;p&gt;The simplest case looks like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;doPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;FormEasy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;youremail@domain.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// To receive email notification(optional)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;FormEasy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Mandatory to return action method&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Deploy the apps script code
&lt;/h3&gt;

&lt;p&gt;After saving all the changes to the code, it has to be deployed to use it. &lt;/p&gt;

&lt;p&gt;To deploy, click the Deploy button at the top right corner and select New deployment and select type to Web app from the gear icon.&lt;/p&gt;

&lt;p&gt;Select/fill the below options&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Description(optional),&lt;/li&gt;
&lt;li&gt;Execute as &lt;strong&gt;Me(you email)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Who has access &lt;strong&gt;Anyone&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Click the &lt;strong&gt;Deploy&lt;/strong&gt; button(authorize the script if you haven't done it before) and you will get a URL under &lt;strong&gt;Web app&lt;/strong&gt;, copy that and it is going to be the endpoint for submitting the POST requests. &lt;/p&gt;

&lt;p&gt;That's it. Now you can submit forms on this endpoint and they get logged in the Google sheet you selected. If you had set email then you will be notified through email whenever any form submission happens.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vk17b0IB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37edue123vqs4na2v1sx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vk17b0IB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37edue123vqs4na2v1sx.png" alt="Deploy apps script code" width="880" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to make any changes to the script, like changing the subject text, email etc, you can do so and save the script. And while redeploying it instead of selecting New deployment, this time you have to select &lt;strong&gt;Manage deployments&lt;/strong&gt; and click the pencil icon, select the &lt;strong&gt;New version&lt;/strong&gt;, and click the deploy button. &lt;/p&gt;

&lt;p&gt;The changes will be get reflected when you make the POST requests after that. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Whenever you make a new deployment, the web app URL changes. But when you redeploy using &lt;strong&gt;&lt;em&gt;Manage deployments&lt;/em&gt;&lt;/strong&gt; option the URL remains the same.&lt;/p&gt;

&lt;p&gt;Here is how a sample POST request using JavaScript &lt;code&gt;fetch&lt;/code&gt; looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;john@domain.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Receiving forms is easy and simple now!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://script.google.com/macros/s/&amp;lt;Deployment ID&amp;gt;/exec&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text/plain;charset=utf-8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;err&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to follow all the above instructions in the form of a video you can check this demo video.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0u75mtnhifM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;As said already FormEasy is an open-source FormSpree alternative. You can check the source code of this library, fork it, make changes, use it yourself or you can contribute your code to the &lt;a href="https://github.com/Basharath/FormEasy"&gt;FormEasy Github repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope this is a good solution to handle contact forms on static websites for FREE. If you have or found any such useful solution for static sites then do share it with me.&lt;/p&gt;

&lt;p&gt;I'll be sharing interesting tips, tricks and hacks about web development and technology on &lt;a href="https://twitter.com/wahVinci"&gt;Twitter @wahVinci&lt;/a&gt; and &lt;a href="https://www.instagram.com/dev_apt/"&gt;Instagram @dev_apt&lt;/a&gt;, follow if you are interested.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Convert text selection to image instantly</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Fri, 22 Apr 2022 15:56:56 +0000</pubDate>
      <link>https://dev.to/basharath/convert-text-selection-to-image-instantly-2656</link>
      <guid>https://dev.to/basharath/convert-text-selection-to-image-instantly-2656</guid>
      <description>&lt;p&gt;There are various types of browser extensions that help to accomplish certain tasks very easily. &lt;/p&gt;

&lt;p&gt;We have already seen one such interesting &lt;a href="https://devapt.com/copy-text-easily-chrome-extension"&gt;chrome extension to copy text&lt;/a&gt; easily as never before just with a click. &lt;/p&gt;

&lt;p&gt;Here is one more such unique chrome extension that helps to convert text to image just instantly.&lt;/p&gt;

&lt;p&gt;Let's see how this text to image extension works and how we can make the best use of it while browsing the web.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate image from text selection
&lt;/h2&gt;

&lt;p&gt;Before going to use this extension you need to first install it from the chrome store. You can get this from the below link. &lt;/p&gt;

&lt;p&gt;➜ &lt;a href="https://chrome.google.com/webstore/detail/text-to-image/nkljaohokglebeljcgchmehnhdieakda"&gt;Text to image chrome extension&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you installed this extension you can find it in the extensions bar and if you can't find it, check it in the dropdown menu of extensions and pin to find it in the main extensions bar. &lt;/p&gt;

&lt;p&gt;In order to use it just visit any website where you can be able to select text or just use this website.&lt;/p&gt;

&lt;p&gt;Select any text you want and then right-click to see the &lt;em&gt;Text to image&lt;/em&gt; option in the right-click menu or specifically the context menu and from there click copy or download. &lt;/p&gt;

&lt;p&gt;That's it you'll have the image of the text that you selected, voila!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7g4zqDuB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqunyijbkn026a211p0t.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7g4zqDuB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqunyijbkn026a211p0t.gif" alt="Text-to-image-chrome-extension" width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to customize the generated image?
&lt;/h3&gt;

&lt;p&gt;You can customize the look of the image that is generated from the selected text with the help of the options available. &lt;/p&gt;

&lt;p&gt;When you click the extension icon you can see three customization options viz., mode, padding, and color palettes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q5zjgb0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgqx3v2g745nzyz2h8jh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q5zjgb0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgqx3v2g745nzyz2h8jh.png" alt="Text-to-image-extension-options" width="680" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Mode 
&lt;/h4&gt;

&lt;p&gt;With the help of the mode option, you can select the light or dark mode for the card that holds the text. &lt;/p&gt;

&lt;p&gt;By default, it is in light mode. &lt;/p&gt;

&lt;h4&gt;
  
  
  2. Padding
&lt;/h4&gt;

&lt;p&gt;The padding refers to the spacing around the text card which helps us to see the background. You have various values to pick from 0px to 128px.&lt;/p&gt;

&lt;p&gt;When you select the 0px(pixels) it will hide the background and all the space will be occupied by the text card.&lt;/p&gt;

&lt;p&gt;When you do not want any fancy background, instead just plain text with a white/dark background, you can make the padding 0px. &lt;/p&gt;

&lt;h4&gt;
  
  
  3. Color palette
&lt;/h4&gt;

&lt;p&gt;From the color palette, you can pick your favorite color backgrounds to show behind the text card. &lt;/p&gt;

&lt;p&gt;These color backgrounds are mostly the gradient colors which make these text images appear nice and attention grabbing. &lt;/p&gt;

&lt;p&gt;Note that when you select 0px padding, these background colors will be hidden as there won't be any space. &lt;/p&gt;

&lt;h4&gt;
  
  
  4. Download 
&lt;/h4&gt;

&lt;p&gt;To quickly download the image just after selecting the text you can use this option for downloading the generated image to your device. &lt;/p&gt;

&lt;p&gt;There are shortcuts for copying and downloading the image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shortcut to copy:&lt;/strong&gt; Ctrl+Shift+Z&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shortcut to download:&lt;/strong&gt; Ctrl+Shift+↓(down arrow)&lt;/p&gt;

&lt;p&gt;Sometimes these shortcuts may conflict with the shortcuts in the browser or some websites. So keep this in mind while trying them out.&lt;/p&gt;

&lt;p&gt;Right-click context menu options are always there whenever you face such issues. &lt;/p&gt;

&lt;h3&gt;
  
  
  Where to use text to image extension?
&lt;/h3&gt;

&lt;p&gt;If you know why this extension was created, and the main problem it wants to address then it would give an idea of where to use this extension effectively. &lt;/p&gt;

&lt;p&gt;There was a situation where I wanted to reply to tweets on Twitter with more than 280 characters, it was difficult or a bit cumbersome to tweet multiple times. &lt;/p&gt;

&lt;p&gt;At that time I thought if there was something that could help me instantly to send messages that are of more than 280 characters without leaving the browser.&lt;/p&gt;

&lt;p&gt;Then an idea struck me to convert the text to an image instantly which then can be shared as a reply to tweets. &lt;/p&gt;

&lt;p&gt;And as a result, this &lt;strong&gt;&lt;em&gt;text to image&lt;/em&gt;&lt;/strong&gt; extension is born.&lt;/p&gt;

&lt;p&gt;So this extension can be used to share long texts as replies/tweets on Twitter. You can also save text info from websites as images for your future reference. &lt;/p&gt;

&lt;p&gt;Sometimes when you want to show text in a fancy and attractive manner you can use it there as well. &lt;/p&gt;

&lt;p&gt;If you want to create more rich text effects including images, code snippets, etc you can try out this full-fledged solution from &lt;a href="https://tweetlet.net/"&gt;tweetlet&lt;/a&gt; website that helps you create amazing and visually appealing images. &lt;/p&gt;

&lt;p&gt;If you want a demo of this extension you can watch this video. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ybaH7ts4xtQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That's it about this interesting tool that helps you to convert any selected text instantly to an image without leaving your browser.&lt;/p&gt;

&lt;p&gt;Please feel free to share any suggestions/feedback/improvements in this tool.&lt;/p&gt;

&lt;p&gt;I'll be sharing interesting tips, tricks and hacks about web development and technology on &lt;a href="https://twitter.com/wahVinci"&gt;Twitter @wahVinci&lt;/a&gt; and &lt;a href="https://www.instagram.com/dev_apt/"&gt;Instagram @dev_apt&lt;/a&gt;, follow if you are interested.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Create beautiful images from text and tweets</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Tue, 15 Mar 2022 08:39:26 +0000</pubDate>
      <link>https://dev.to/basharath/create-beautiful-images-from-markdown-text-and-tweets-4f00</link>
      <guid>https://dev.to/basharath/create-beautiful-images-from-markdown-text-and-tweets-4f00</guid>
      <description>&lt;p&gt;In this social media era, information gets shared in various forms. Text, image, and video are the quite commonly used media formats on the internet.&lt;/p&gt;

&lt;p&gt;Images are the commonly used format for displaying information in an attractive way. Images are easy to save and share info. &lt;/p&gt;

&lt;p&gt;Images and videos are also the preferred media formats for getting good engagement for your posts on social media. &lt;/p&gt;

&lt;p&gt;It's a good idea to convert text to images that are attractive and informative, which is nothing but called infographics. &lt;/p&gt;

&lt;p&gt;Here is a tool using which you can convert text, tweet, or any other image into a beautiful image with an attractive background to share on different social media platforms.&lt;/p&gt;

&lt;p&gt;The tool is called &lt;a href="https://tweetlet.net/"&gt;tweetlet&lt;/a&gt; and the images generated by it are called tweetlets. &lt;/p&gt;

&lt;p&gt;Let's learn more about this tweetlet tool to make cool photos out of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create beautiful images using tweetlet
&lt;/h2&gt;

&lt;p&gt;Tweetlet.net site has three different modes for creating images from:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tweet to image&lt;/li&gt;
&lt;li&gt;Image to a beautiful image with background&lt;/li&gt;
&lt;li&gt;Text to image&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To switch to a particular mode, just hover/click on the icon in the search bar, and using that you can switch to a tweet or image, or text mode.&lt;/p&gt;

&lt;p&gt;The image can be resized with the help of the white clips provided on the edge of the image. Dragging by holding those resizers(white clips) will resize the image. &lt;/p&gt;

&lt;p&gt;In every mode, there are two buttons for copying and downloading the image. Besides that, you can select the desired background from the preset gradients and adjust the image to a ready-made aspect ratio of 1:1 or 2:1.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Mu82_swa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e70wt3m4va8zmf1pqcq9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Mu82_swa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e70wt3m4va8zmf1pqcq9.png" alt="create-images-from-text" width="880" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Tweet to image
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GZRWYJB_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zjvw7o2wncd453sg8d9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GZRWYJB_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zjvw7o2wncd453sg8d9.png" alt="Tweetlet-tweet-to-image" width="880" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To convert any &lt;a href="https://tweetlet.net/tweet"&gt;tweet to an image&lt;/a&gt; just copy the tweet's link and paste it in the search box of the tweetlet website. &lt;/p&gt;

&lt;p&gt;It will create a beautiful quote-like image by default. With the help of controls, you can change it to a tweet mode from quote to make it appear exactly like the actual tweet.&lt;/p&gt;

&lt;p&gt;With the help of controls, you can also adjust the size of the text, toggle the likes and shares of a tweet, change the background with various preset gradients. &lt;/p&gt;

&lt;p&gt;Finally, when you are satisfied with the image, click copy or download it. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Image to a beautiful image with a background
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M19ATauS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4u2qh6u9muwzdd40na32.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M19ATauS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4u2qh6u9muwzdd40na32.png" alt="Tweetlet-to-image" width="880" height="547"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://tweetlet.net/image"&gt;image mode of tweetlet&lt;/a&gt;, you can upload or paste any image directly in the tweetlet site and it will appear with a cool background.&lt;/p&gt;

&lt;p&gt;You can resize the image with the help of the resizers. &lt;/p&gt;

&lt;p&gt;A cool trick to create a stack-effect image is to copy the current image and paste it and repeat until the stack level you want.&lt;/p&gt;

&lt;p&gt;You can change the background as per your interest and finally copy or download the image to share it on any platform you want.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Text to image
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--huBfYfTR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfgwzhg5bk7qyfhj1fj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--huBfYfTR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfgwzhg5bk7qyfhj1fj6.png" alt="Tweetlet-text-to-image" width="880" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the most powerful way to convert various kinds of text into a beautiful image. &lt;/p&gt;

&lt;p&gt;First, switch to the &lt;a href="https://tweetlet.net/text"&gt;text mode&lt;/a&gt; and you'll see a text box with a resizer at the bottom, dragging which you can resize the height of the text box. &lt;/p&gt;

&lt;p&gt;This text box supports markdown text. That means you can have rich text effects using this. &lt;/p&gt;

&lt;p&gt;Syntax for the rich text as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sVATot-M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxfqu1uh6osy7ey7qwci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sVATot-M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxfqu1uh6osy7ey7qwci.png" alt="Tweetlet-markdown-syntax" width="603" height="680"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mentioning the correct language will enable to highlight the code as per that language, else it will show just a plain pre-formatted text. &lt;/p&gt;

&lt;p&gt;Using the markdown syntax, you can even embed other images along with your text to create beautiful images using all of it.&lt;/p&gt;

&lt;p&gt;You can learn more about the markdown syntax &lt;a href="https://www.markdownguide.org/basic-syntax/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Text mode will be useful for sharing code snippets and rich text info easily as an image. &lt;/p&gt;

&lt;p&gt;If you want to create images instantly just by selecting the text you can check this &lt;a href="https://chrome.google.com/webstore/detail/text-to-image/nkljaohokglebeljcgchmehnhdieakda"&gt;text to image&lt;/a&gt; chrome extension that generates images from selected text in the blink of the eye.&lt;/p&gt;

&lt;p&gt;As usual, once you are satisfied with all the adjustments, you can copy or download the image to share it on any platform you wanted. &lt;/p&gt;

&lt;p&gt;You can see few other things that can be done using markdown. ↓&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XLU_mcC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/md43z0ot4x6ua21l2uk5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XLU_mcC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/md43z0ot4x6ua21l2uk5.png" alt="Tweetlet-markdown-demo" width="880" height="1151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's a dark mode icon at the top right corner where you can switch to the dark mode or light mode based on your preference. Your gradient and mode settings will be stored locally so whenever you open the site your previous settings get reflected. &lt;/p&gt;

&lt;p&gt;You can directly try out all the above-mentioned modes from &lt;a href="https://tweetlet.net/"&gt;tweetlet.net&lt;/a&gt; right away. And if you want any new features you can send a message/feedback from the message icon present at the bottom right corner. &lt;/p&gt;

&lt;p&gt;Last but not the least, if you like this tweetlet tool, then do share it with your friends.&lt;/p&gt;

&lt;p&gt;I'll be sharing interesting tips, tricks and hacks about web development and technology on &lt;a href="https://twitter.com/wahVinci"&gt;Twitter @wahVinci&lt;/a&gt; and &lt;a href="https://www.instagram.com/dev_apt/"&gt;Instagram @dev_apt&lt;/a&gt;, follow if you are interested.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Launched my first product on Product Hunt</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Wed, 16 Feb 2022 16:18:29 +0000</pubDate>
      <link>https://dev.to/basharath/launched-my-first-product-on-product-hunt-415i</link>
      <guid>https://dev.to/basharath/launched-my-first-product-on-product-hunt-415i</guid>
      <description>&lt;p&gt;I'm Basharath, a full-stack developer. I’ve always been interested in solving problems and developing interesting tools to address them.&lt;/p&gt;

&lt;p&gt;This is my very first product on ProductHunt. Very much excited to launch. 😀&lt;/p&gt;

&lt;p&gt;A few days ago when I was doing some work involving copying text paragraphs and sentences, I noticed that it was tedious work to carry out. Using Ctrl + C all the time for copying text seemed to be a bit time-consuming thing for me.&lt;/p&gt;

&lt;p&gt;At that time I felt like to have some tool to copy text or sentences just in a click. I tried finding if there's any tool that could address this problem and I found none.&lt;/p&gt;

&lt;p&gt;So I decided to create one myself addressing various scenarios involved while copying text on the web.&lt;/p&gt;

&lt;p&gt;Here is that tool addressing those problems involved while copying text. It is called &lt;a href="https://devapt.com/copy-text-easily"&gt;Copy Text Easily&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is a chrome extension that lets you copy text or code snippets in a hassle-free manner just with a click.&lt;/p&gt;

&lt;p&gt;You can have a look at the &lt;a href="https://www.producthunt.com/posts/copy-text-easily"&gt;Copy text easily product&lt;/a&gt; on the Product Hunt and give your feedback.&lt;/p&gt;

&lt;p&gt;Here is the intro video.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vpSypDZdJcE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Copy text/codes in a click from any site</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Mon, 17 Jan 2022 10:22:45 +0000</pubDate>
      <link>https://dev.to/basharath/never-seen-way-of-copying-text-or-code-snippets-2mb8</link>
      <guid>https://dev.to/basharath/never-seen-way-of-copying-text-or-code-snippets-2mb8</guid>
      <description>&lt;p&gt;We often copy text or code snippets or any other kind of resource quite commonly while browsing the web. Copying sometimes got to be tedious work in certain situations.&lt;/p&gt;

&lt;p&gt;Using keyboard shortcuts quite often for various tasks is found to be a great time-saver in the long run. But certain people who are not much used to a keyboard, like using the mouse for all their small to big activities in the browser.&lt;/p&gt;

&lt;p&gt;Copying and pasting text with the shortcuts &lt;code&gt;Ctrl + C&lt;/code&gt; and &lt;code&gt;Ctrl + V&lt;/code&gt;  are the world's highly used shortcuts and these shortcuts are known almost to all the people who use a computer.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Do you remember yourself copying text with &lt;code&gt;Ctrl + C C C C C C C&lt;/code&gt;, typing C multiple times to make sure the text gets copied?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sometimes we tend to put a bit more time even with copy shortcuts. When you want to copy text just so frequently, let's say you want to shift a formatted text from one place to the other and that can be copied only as paragraphs and not as a whole, in such situations, copying and pasting text with even shortcuts is going to be a very tedious job. Not just this case but in any case that involves frequent copying and pasting text gets tedious even with shortcuts.&lt;/p&gt;

&lt;p&gt;So keeping in mind various contexts involved in copying text, a small and compact chrome extension is made to &lt;em&gt;&lt;a href="https://devapt.com/copy-text-easily"&gt;Copy Text Easily&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Using Copy Text Easily(CTE) extension effectively has the potential to save a lot of time in the long run for those who involve in copying text just so frequently. e.g., Students copying reference details to their journals, etc.&lt;/p&gt;

&lt;p&gt;Let's see all the features which this Copy Text Easily extension provides.&lt;/p&gt;

&lt;h2&gt;
  
  
  Copy Text Easily extension
&lt;/h2&gt;

&lt;p&gt;Before getting started to use this Copy Text Extension, you need to first install it from the chrome store. You can install the extension from this link &lt;a href="https://chrome.google.com/webstore/detail/copy-text-easily/fagmaopcbeobbfhkeodicjekiniefdlo"&gt;Copy Text Easily Extension&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  CTE chrome extension has got three modes for copying text
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Paragraph(default)&lt;/li&gt;
&lt;li&gt;Sentence&lt;/li&gt;
&lt;li&gt;Custom&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Paragraph mode:
&lt;/h3&gt;

&lt;p&gt;In paragraph mode, you can copy the blocks of text by hovering on any block of text you want. A small preview of the text that you are going to copy will be displayed for convenience. Just clicking on the block of text will get the text copied. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--riKQ8_TB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iv4gqxos1znnd3emwvyf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--riKQ8_TB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iv4gqxos1znnd3emwvyf.gif" alt="copy-code-stackoverflow-copy-text-easily" width="880" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This mode is very useful for copying blocks of code or code snippets on StackOverflow, GitHub, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Sentence mode:
&lt;/h3&gt;

&lt;p&gt;This is a very unique way to copy sentences from a paragraph. By hovering the mouse on and off the paragraph, you can see different sentences getting selected to copy the text. Whichever sentence you want can be seen in the preview box and just clicking once will get that particular sentence copied to your clipboard. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KlpRvPJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ub6oa1geu2f29l1qyz8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KlpRvPJ_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ub6oa1geu2f29l1qyz8.gif" alt="sentence-mode-copy-text-easily" width="880" height="427"&gt;&lt;/a&gt;&lt;br&gt;
This mode is very useful while working with sentences related to writing works. &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Custom mode:
&lt;/h3&gt;

&lt;p&gt;This is the customized mode to copy any text you want just by selecting. Yes, just selecting a text will copy the text to the clipboard. This is useful in situations when you can want to copy a very specific text when it is not possible with the above previous modes. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KDuNlo54--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oyl96bylov4totzqmmqx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KDuNlo54--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oyl96bylov4totzqmmqx.gif" alt="custom-mode-copy-text-easily" width="880" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, the extension will be active on the active browser tab, and the mouse hovering will result in the preview of text hovered. So to avoid that there's an option to activate this extension on demand by pressing any of &lt;code&gt;Ctrl&lt;/code&gt;, &lt;code&gt;Alt&lt;/code&gt;, &lt;code&gt;Shift&lt;/code&gt; keys. You can select the key at your convenience from the extension keypress options. &lt;/p&gt;

&lt;p&gt;There's even an option to enable or disable the whole extension and the keypress mode. &lt;/p&gt;

&lt;p&gt;Coming to privacy, this extension fully runs on your browser locally and doesn't communicate with the outside world. It is packed in under 15KB of pure JavaScript code without any libraries or frameworks. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you face any problems with this extension you can try the below methods:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Reload the page whichever is having a problem&lt;/li&gt;
&lt;li&gt; Check if the extension is enabled&lt;/li&gt;
&lt;li&gt; Check if you have enabled the extension to work only on keypress&lt;/li&gt;
&lt;li&gt; Sometimes 'Shift' and 'Alt' keys might have problems, so try to select the 'Ctrl' key if you have problems&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that is all about this simple chrome extension to copy the text in a hassle-free manner.&lt;/p&gt;

&lt;p&gt;I'll be sharing interesting tips, tricks and hacks about web development and technology on &lt;a href="https://twitter.com/wahVinci"&gt;Twitter @wahVinci&lt;/a&gt; and &lt;a href="https://www.instagram.com/dev_apt/"&gt;Instagram @dev_apt&lt;/a&gt;, follow if you are interested.&lt;/p&gt;

&lt;p&gt;P.S: I'm going to make a tutorial to create extension like this soon, until then support me by following and sharing this article on Twitter.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Way to customize each item in the list using simple CSS</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Thu, 13 Jan 2022 07:12:55 +0000</pubDate>
      <link>https://dev.to/basharath/customize-each-list-item-style-with-this-simple-css-jbc</link>
      <guid>https://dev.to/basharath/customize-each-list-item-style-with-this-simple-css-jbc</guid>
      <description>&lt;p&gt;Lists are the form of data representation commonly used by all types of documents. In HTML there are two types of lists namely ordered and unordered lists. &lt;/p&gt;

&lt;p&gt;In an ordered list, the items are indicated by serial numbers or letters that are in some order. In an unordered list, the list items are indicated by various types of bullets viz., disc, circle, square, or by an image. &lt;/p&gt;

&lt;p&gt;By default, the ordered list items are indicated by numbers and unordered list items by disc bullets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Unordered list --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Ordered list --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ol&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ol&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1641977633472%2FBkjwpjzgm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1641977633472%2FBkjwpjzgm.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling list style types
&lt;/h2&gt;

&lt;p&gt;For styling lists, there are CSS list properties using which we can change the list style type, list position, and add an image as a list type nothing but the image as the bullet of the list item.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS list property
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;ol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* list-style is a shorthand property */&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;list-style-type&lt;/span&gt; &lt;span class="n"&gt;list-style-position&lt;/span&gt; &lt;span class="n"&gt;list-style-image&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;list-style-type&lt;/code&gt; - to change the bullet styles of the list&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;list-style-position&lt;/code&gt; - to change the position of the list, two values outside and inside&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;list-style-image&lt;/code&gt; - to add an image as a bullet for the list, if the image fails to show then list-style-type will be shown&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So in order to change the bullet type for the list, we just need to use CSS list style type with the bullet we need. Let's see how to change the bullets for the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Unordered list */&lt;/span&gt;
&lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'❤️'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="err"&gt;or&lt;/span&gt; &lt;span class="c"&gt;/* list-style: '❤️'; */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Orderedlist */&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'👍'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1641977591471%2FNqpRKa_ek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1641977591471%2FNqpRKa_ek.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just by changing the CSS list style type value, we can change the bullets of any list. The possible value for the list style type can be anything, even language-specific letters, roman numerals, etc. To know various supported list style types in CSS head over to &lt;a href=""&gt;this MDN Docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But using this way all the style types are going to be the same for all the items of the list. In order to customize style type for every individual item, we need to define it by using CSS at-rule, &lt;code&gt;@counter-style&lt;/code&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Customize individual list style type
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;@counter-style&lt;/code&gt; we can define the custom list style type for individual items of the list. It has so many properties for customizing the list. There are three important properties that we need to know to customize the list style types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@counter-style&lt;/span&gt; &lt;span class="n"&gt;custom-type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;system&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cyclic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"😀"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;suffix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;custom-type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/*or list-style-type: custom-type; */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;system&lt;/code&gt; - defines how the list bullets should show. The possible values for it are: cyclic, numeric, alphabetic, symbolic, additive, or fixed, etc&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;symbols&lt;/code&gt; - here is where you need to give different list style types you want to show for the list items. It can be numbers, alphabets, symbols, even images separated by a space&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;suffix&lt;/code&gt; - usually, this one should be space, to have a space after the style type. Other than space you can have anything as a suffix.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's see all the above in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Unordered list --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;One&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Two&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Three&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Four&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Ordered list --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ol&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;One&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Two&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Three&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Four&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ol&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* style type for unordered list */&lt;/span&gt;
&lt;span class="k"&gt;@counter-style&lt;/span&gt; &lt;span class="n"&gt;custom-unordered&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;system&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cyclic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="s2"&gt;'❓'&lt;/span&gt; &lt;span class="s2"&gt;'✌️'&lt;/span&gt; &lt;span class="s2"&gt;'❤️'&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;suffix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* style type for ordered list */&lt;/span&gt;
&lt;span class="k"&gt;@counter-style&lt;/span&gt; &lt;span class="n"&gt;custom-ordered&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;system&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'➡️'&lt;/span&gt; &lt;span class="s2"&gt;'😀'&lt;/span&gt; &lt;span class="s2"&gt;'👍'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;suffix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;custom-unordered&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/* or list-style-type: custom-unordered; */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style-type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;custom-ordered&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1641977791593%2FuO54HIt7W.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1641977791593%2FuO54HIt7W.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image of the result is put here because we can't edit the CSS in dev.to. To see the actual result on the webpage, see the original article on the &lt;a href="https://devapt.com/customize-css-list-style-type" rel="noopener noreferrer"&gt;devapt&lt;/a&gt; site.&lt;/p&gt;

&lt;p&gt;So using the @counter-style that is how we can add individual list style types. If you see when &lt;code&gt;system&lt;/code&gt; is defined as &lt;code&gt;cyclic&lt;/code&gt; the same list style type repeats after all types are done, and when it is &lt;code&gt;fixed&lt;/code&gt; the style type for the item number more than the number of symbols defined, get the default style type i.e., a number for the ordered list and disc for the unordered list.&lt;/p&gt;

&lt;p&gt;You need &lt;code&gt;system&lt;/code&gt; value as &lt;code&gt;fixed&lt;/code&gt; only when you know that the number of items are fixed else it's better to go for &lt;code&gt;cyclic&lt;/code&gt; or any other type. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Safari is the only modern browser that doesn't support this CSS feature. You can see the compatibility &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@counter-style#browser_compatibility" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That is all about styling the individual list item types using CSS.&lt;/p&gt;

&lt;p&gt;I'll be sharing interesting tips, tricks and hacks about web development and technology on &lt;a href="https://twitter.com/wahVinci" rel="noopener noreferrer"&gt;Twitter @wahVinci&lt;/a&gt; and &lt;a href="https://www.instagram.com/dev_apt/" rel="noopener noreferrer"&gt;Instagram @dev_apt&lt;/a&gt;, follow if you are interested.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Use URL() instead of URLSearchParams() for query params in JavaScript</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Mon, 10 Jan 2022 09:31:27 +0000</pubDate>
      <link>https://dev.to/basharath/you-just-need-url-instead-of-urlsearchparams-for-query-params-2od1</link>
      <guid>https://dev.to/basharath/you-just-need-url-instead-of-urlsearchparams-for-query-params-2od1</guid>
      <description>&lt;p&gt;Reading and manipulating URLs or query strings is involved in various applications for obtaining data from requests and routing users or requests. Different languages have different ways to deal with query parameters or routing at the backend. &lt;/p&gt;

&lt;p&gt;In this article, we're going to look at the ways to read and manipulate query strings and URLs using &lt;code&gt;URL&lt;/code&gt; and &lt;code&gt;URLSearchParams&lt;/code&gt; APIs of Javascript at the client or more specifically in the browser.&lt;/p&gt;

&lt;p&gt;In the browser, there's a global variable called &lt;code&gt;location&lt;/code&gt; or &lt;code&gt;window.location&lt;/code&gt; using which we can get various details about the URL of your active browser tab. Using location property we can get details like full URL, protocol, host, hostname, port, pathname, search params as a string, etc&lt;/p&gt;

&lt;p&gt;But to parse and read any URL other than our active tab address, we have &lt;code&gt;URL&lt;/code&gt; and &lt;code&gt;URLSearchParams&lt;/code&gt; APIs at our disposal in JavaScript. &lt;/p&gt;

&lt;p&gt;Let's get into more details of these JavaScript APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use URL API in JS?
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;URL&lt;/code&gt; constructor is used to construct, normalize, parse and encode URLs. It provides various properties to read and manipulate the components of a URL.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;URL&lt;/code&gt; takes an absolute URL string as an argument and returns an object with various properties to read and manipulate the passed URL. &lt;/p&gt;

&lt;p&gt;Let's understand this &lt;code&gt;URL&lt;/code&gt; by using a sample URL with query params.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsedUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com/?name=John Smith&amp;amp;age=25&amp;amp;id=101&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parsedUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// https://example.com/?name=John%20Smith&amp;amp;age=25&amp;amp;id=101&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we can see that &lt;code&gt;URL&lt;/code&gt; could parse the supplied URL string correctly. The &lt;code&gt;parsedUrl&lt;/code&gt; can be used as a string directly anywhere we want or we can use the various properties and methods attached to it by the &lt;code&gt;URL&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;URL&lt;/code&gt; has got most of the properties similar to the &lt;code&gt;window.location&lt;/code&gt; object which includes &lt;code&gt;host&lt;/code&gt;, &lt;code&gt;hostname&lt;/code&gt;, &lt;code&gt;href&lt;/code&gt;, &lt;code&gt;origin&lt;/code&gt;, &lt;code&gt;port&lt;/code&gt;, &lt;code&gt;protocol&lt;/code&gt;, &lt;code&gt;search&lt;/code&gt;, &lt;code&gt;searchParams&lt;/code&gt;, &lt;code&gt;username&lt;/code&gt;, &lt;code&gt;password&lt;/code&gt; etc.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com:8080/blog/?name=John Smith&amp;amp;age=25&amp;amp;id=101#heading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;host&lt;/span&gt; &lt;span class="c1"&gt;// example.com:8080&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt; &lt;span class="c1"&gt;// example.com&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt; &lt;span class="c1"&gt;// https://example.com:8080/blog/?name=John%20Smith&amp;amp;age=25&amp;amp;id=101#heading&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;origin&lt;/span&gt; &lt;span class="c1"&gt;// https://example.com:8080&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt; &lt;span class="c1"&gt;// /blog/&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="c1"&gt;// 8080&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;protocol&lt;/span&gt; &lt;span class="c1"&gt;// https:&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hash&lt;/span&gt; &lt;span class="c1"&gt;// #heading&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt; &lt;span class="c1"&gt;// ?name=John%20Smith&amp;amp;age=25&amp;amp;id=101&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt; &lt;span class="c1"&gt;// URLSearchParams {}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So by using &lt;code&gt;URL&lt;/code&gt; API we can get various types of info about the URL link that we pass.&lt;/p&gt;

&lt;p&gt;If you observe the prop &lt;code&gt;url.searchparams&lt;/code&gt; is actually returning the &lt;code&gt;URLSearchParams&lt;/code&gt; which we are going to see in the next section.&lt;/p&gt;

&lt;p&gt;In certain URLs, we have username and password in the URL itself, and such URLs can be parsed easily to get username and password details using this &lt;code&gt;URL&lt;/code&gt; API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://john:somePass@dev.example.com/api/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newUrl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// john&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newUrl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// somePass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To modify any of the props we can just simply assign any valid value to it.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com:8080/blog/?name=John Smith&amp;amp;age=25&amp;amp;id=101#heading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://abc.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;about&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#important&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;?name=Bond&amp;amp;age=20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// https://abc.com/about?name=Bond&amp;amp;age=20#important&lt;/span&gt;

&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://aaa.com:7777&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// Error: Cannot set property origin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can set or modify any of the properties of &lt;code&gt;url&lt;/code&gt; except &lt;code&gt;origin&lt;/code&gt; and &lt;code&gt;searchParams&lt;/code&gt; if you try, an error will be thrown. &lt;/p&gt;
&lt;h2&gt;
  
  
  How to use URLSearchParams in JS?
&lt;/h2&gt;

&lt;p&gt;In the last section we have seen the ways to read and modify URLs but reading and setting individual URL query strings can be done easily using the &lt;code&gt;URLSearchParams&lt;/code&gt; constructor. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;URLSearchParams&lt;/code&gt; takes the query string of a URL as argument and returns an iterable object with various methods to read and manipulate the query parameters. If you pass a full URL to the &lt;code&gt;URLSearchParams&lt;/code&gt; it will clip off the inital param after &lt;code&gt;?&lt;/code&gt;. So it's always good to pass only the query string part of the URL or just pass query string as an object with key value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com/blog?name=john&amp;amp;age=25&amp;amp;id=101&amp;amp;name=smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;searchParams&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// For active browser link, use location.search&lt;/span&gt;

&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// john&lt;/span&gt;
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ["john", "smith"]&lt;/span&gt;
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;age&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// name=john&amp;amp;age=25&amp;amp;id=101&amp;amp;name=smith&lt;/span&gt;
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;place&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Munich&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Adding a new query param&lt;/span&gt;
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;222&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Updating the id to 222&lt;/span&gt;
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// name=john&amp;amp;age=25&amp;amp;id=222&amp;amp;name=smith&amp;amp;place=Munich&lt;/span&gt;
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;place&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// name=john&amp;amp;age=25&amp;amp;id=222&amp;amp;name=smith&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are other methods like &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;entries&lt;/code&gt; and &lt;code&gt;forEach&lt;/code&gt;(iterates over the values) to iterate the search params. &lt;/p&gt;

&lt;p&gt;Other than &lt;code&gt;forEach&lt;/code&gt; method all return iterables so array methods like forEach can't be run on those. We need to convert them to an array and use methods like forEach, map etc.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;searchParams&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name=john&amp;amp;age=25&amp;amp;id=101&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// john 25 101&lt;/span&gt;
&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;k&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// name age id&lt;/span&gt;
&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// john 25 101&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// {name: "john", age: "25", id: "101"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code snippet for the methods &lt;code&gt;keys&lt;/code&gt;, &lt;code&gt;values&lt;/code&gt; and &lt;code&gt;entries&lt;/code&gt; we converted them to arrays and object to see the results.&lt;/p&gt;

&lt;p&gt;Now if we go back to the &lt;code&gt;URL&lt;/code&gt; API methods, we have &lt;code&gt;searchParams&lt;/code&gt; method there, using that we can get all the details that we could get using &lt;code&gt;URLSearchParams&lt;/code&gt; except that we cannot set any query parameters from there.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com/?name=John Smith&amp;amp;age=25&amp;amp;id=101&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// John Smith&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;age&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//name=John+Smith&amp;amp;age=25&amp;amp;id=101&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;//John Smith 25 101&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// {name: "John Smith", age: "25", id: "101"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Using URL we can pass full URL address and can still read the correct query params unlike URLSearchParams where we need to pass only the query string to read the correct query parameters data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So that's all about &lt;code&gt;URL&lt;/code&gt; and &lt;code&gt;URLSearchParams&lt;/code&gt; in Javascript. In conclusion what we can infer is in most of the cases to read the query strings we you just need to use &lt;code&gt;URL&lt;/code&gt; API.&lt;/p&gt;

&lt;p&gt;If you liked this article please give a follow &amp;amp; share. More such interesting articles are on the way.&lt;/p&gt;

&lt;p&gt;I'll be sharing interesting tips, tricks and hacks about web development and technology on &lt;a href="https://twitter.com/wahVinci"&gt;Twitter @wahVinci&lt;/a&gt; and &lt;a href="https://www.instagram.com/dev_apt/"&gt;Instagram @dev_apt&lt;/a&gt;, follow if you are interested.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Easiest way to understand CAB(Call, Apply, Bind) in JS</title>
      <dc:creator>Basharath</dc:creator>
      <pubDate>Fri, 07 Jan 2022 15:40:18 +0000</pubDate>
      <link>https://dev.to/basharath/easiest-way-to-understand-cabcall-apply-bind-in-js-1l2h</link>
      <guid>https://dev.to/basharath/easiest-way-to-understand-cabcall-apply-bind-in-js-1l2h</guid>
      <description>&lt;p&gt;The keyword &lt;code&gt;this&lt;/code&gt; in JavaScript is one of the most muddling concepts because its value depends on where it is used. Often it tricks developers and sometimes it's the culprit behind surreal results.&lt;/p&gt;

&lt;p&gt;Let's discuss this &lt;code&gt;this&lt;/code&gt; keyword with simple and easy-to-understand examples before actually delving into the &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, and &lt;code&gt;bind&lt;/code&gt; methods as &lt;code&gt;this&lt;/code&gt; keyword is the main reason for having those methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is this in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;this&lt;/code&gt; keyword in JavaScript refers to the object that the function is a property of and &lt;code&gt;this&lt;/code&gt; will depend on the object that is invoking the function. &lt;/p&gt;

&lt;p&gt;To get a quick idea of &lt;code&gt;this&lt;/code&gt; have a look at the code snippet below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;place&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;London&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;myObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="c1"&gt;// {name: "John", age: 25, place: "London", myFunction: ƒ()}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code snippet, you can see that when &lt;code&gt;myFunction&lt;/code&gt; method is called it returns the value of &lt;code&gt;this&lt;/code&gt;, which is nothing but the &lt;code&gt;myObj&lt;/code&gt; itself. If you recollect the definition for &lt;code&gt;this&lt;/code&gt; in the previous paragraph, it says &lt;code&gt;this&lt;/code&gt; refers to the object that the function is a property of, so here &lt;code&gt;myFunction&lt;/code&gt; is a property of &lt;code&gt;myObj&lt;/code&gt;, which means &lt;code&gt;this&lt;/code&gt; is referring to that myObj object. &lt;/p&gt;

&lt;p&gt;A simple trick is whatever precedes before .(dot) is the object referenced by the &lt;code&gt;this&lt;/code&gt; keyword. So before .(dot) in &lt;code&gt;myObj.myFunction()&lt;/code&gt; is &lt;code&gt;myObj&lt;/code&gt;, which is the value of &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's take another example to understand this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;myFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// window or undefined(in case of 'strict mode')&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code we are returning &lt;code&gt;this&lt;/code&gt; from the &lt;code&gt;myFunction&lt;/code&gt;, so when &lt;code&gt;myFunction&lt;/code&gt; is called what we see or get is the value of &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Again if we recollect our definition of &lt;code&gt;this&lt;/code&gt;, it refers to the object which the function is a property of. Here our function &lt;code&gt;myFunction&lt;/code&gt; is a property of global object nothing but the &lt;code&gt;window&lt;/code&gt; object in the browser, so which means when we call &lt;code&gt;myFunction&lt;/code&gt; the value of &lt;code&gt;this&lt;/code&gt; is going to be the &lt;code&gt;window&lt;/code&gt; object. &lt;/p&gt;

&lt;p&gt;If we go by our trick of .(dot) preceding the function, here there's no dot but every function is a method in the &lt;code&gt;window&lt;/code&gt; object, so it translates to &lt;code&gt;window.myFunction()&lt;/code&gt; so here, the &lt;code&gt;this&lt;/code&gt; keyword refers to the &lt;code&gt;window&lt;/code&gt; object. &lt;/p&gt;

&lt;p&gt;In order to avoid functions getting attached to the window object, we &lt;code&gt;use strict&lt;/code&gt; mode so as a result window will be &lt;code&gt;undefined&lt;/code&gt; in such cases. &lt;/p&gt;

&lt;p&gt;So keep in mind our definition as we're going to use that for understanding &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;bind&lt;/code&gt; methods. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The this keyword in JavaScript refers to the object that the function is a property of and this will depend on the object that is invoking the function. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Understanding call, apply, bind in JavaScript
&lt;/h2&gt;

&lt;p&gt;Let's consider an object &lt;code&gt;person&lt;/code&gt; with a property &lt;code&gt;name&lt;/code&gt; and a method &lt;code&gt;details&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;details&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;place&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old, lives in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;place&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;London&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//John 25 years old, lives in London&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we call the method &lt;code&gt;details&lt;/code&gt; on &lt;code&gt;person&lt;/code&gt; object with the arguments, we knew that &lt;code&gt;this&lt;/code&gt; refers to the &lt;code&gt;person&lt;/code&gt; object because &lt;code&gt;details&lt;/code&gt; is a property of the &lt;code&gt;person&lt;/code&gt; object and so &lt;code&gt;this.name&lt;/code&gt; would be &lt;em&gt;John&lt;/em&gt; and so the result that gets returned will be as shown in the comments.&lt;/p&gt;

&lt;p&gt;This part is going to be clear as we knew what &lt;code&gt;this&lt;/code&gt; means in the &lt;code&gt;person&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;Let's consider a scenario where we wanted to use the &lt;code&gt;details&lt;/code&gt; method but with different arguments.&lt;/p&gt;

&lt;p&gt;As per the &lt;code&gt;details&lt;/code&gt; method we can pass in different age and place values but how about the name, as it is connected with the &lt;code&gt;this&lt;/code&gt; keyword? This is where we are going to use those special methods &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;bind&lt;/code&gt;. Let's dive into those.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;call&lt;/code&gt; method
&lt;/h3&gt;

&lt;p&gt;Now we want to associate a different object other than &lt;code&gt;person&lt;/code&gt; to &lt;code&gt;this&lt;/code&gt; keyword of &lt;code&gt;details&lt;/code&gt; method. So to do that we're going to use the &lt;code&gt;call&lt;/code&gt; method as shown below in the code snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;James&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tokyo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// James 30 years old, lives in Tokyo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;call&lt;/code&gt; method takes a new object that we want this to refer to followed by the arguments to the function(nothing but the &lt;code&gt;details&lt;/code&gt; method) and it gets called referencing &lt;code&gt;this&lt;/code&gt; to the new object passed as the first argument. Voila! That's what a call method is. &lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;apply&lt;/code&gt; method
&lt;/h3&gt;

&lt;p&gt;Guess what, &lt;code&gt;apply&lt;/code&gt; method is just the same as the &lt;code&gt;call&lt;/code&gt; method, that is, it takes a new object as the first argument to reference the &lt;code&gt;this&lt;/code&gt; keyword and is followed by an array of arguments. So it means you can simply pass the arguments to the &lt;code&gt;details&lt;/code&gt; function in the form of an array instead of passing individually. Have a look at the code below so it becomes clear for you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;James&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tokyo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; 
&lt;span class="c1"&gt;// James 30 years old, lives in Tokyo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So &lt;code&gt;call&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt; methods are used to reference a new object to &lt;code&gt;this&lt;/code&gt; keyword on methods.&lt;/p&gt;

&lt;p&gt;And then what &lt;code&gt;bind&lt;/code&gt; is for? Guess!&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;bind&lt;/code&gt; method
&lt;/h3&gt;

&lt;p&gt;When &lt;code&gt;call&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt; methods are applied they are called(invoked) directly referencing the new object passed but in order to get a new function reference that can be used to call at later times, the &lt;code&gt;bind&lt;/code&gt; method is used. Have a look at the code snippet below to get more clarity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;personDetails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;William&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rome&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;personDetails&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="c1"&gt;// William 40 years old, lives in Rome&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So using the &lt;code&gt;bind&lt;/code&gt; method returns a new function reference which can be called at a later time and that is all about the bind method.&lt;/p&gt;

&lt;p&gt;So putting all the three methods together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;details&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;place&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years old, lives in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;place&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;London&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//John 25 years old, lives in London&lt;/span&gt;

&lt;span class="c1"&gt;// Using call&lt;/span&gt;
&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;James&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tokyo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// James 30 years old, lives in Tokyo&lt;/span&gt;

&lt;span class="c1"&gt;// Using apply&lt;/span&gt;
&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;James&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tokyo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// James 30 years old, lives in Tokyo&lt;/span&gt;

&lt;span class="c1"&gt;// Using bind&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;personDetails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;William&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rome&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;personDetails&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// William 40 years old, lives in Rome&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in short CAB(call, apply, bind in JavaScript) are used to reference a new owner object to the &lt;code&gt;this&lt;/code&gt; keyword. Hope this article has demystified the call, apply and bind methods in JS.&lt;/p&gt;

&lt;p&gt;Did we miss anything here? Yes, the &lt;code&gt;this&lt;/code&gt; value will be different when we use an arrow function. See you in the next article.&lt;/p&gt;

&lt;p&gt;If you liked this article please give a follow &amp;amp; share. More such interesting articles are on the way.&lt;/p&gt;

&lt;p&gt;I'll be sharing interesting tips, tricks and hacks about web development and technology on &lt;a href="https://twitter.com/wahVinci"&gt;Twitter @wahVinci&lt;/a&gt; and &lt;a href="https://www.instagram.com/dev_apt/"&gt;Instagram @dev_apt&lt;/a&gt;&lt;/p&gt;

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