<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Srinivasan K K</title>
    <description>The latest articles on Forem by Srinivasan K K (@srinivasankk).</description>
    <link>https://forem.com/srinivasankk</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%2F123756%2Fbf29a2ee-1af6-4b5e-ba9a-8fb95ce32ae8.jpeg</url>
      <title>Forem: Srinivasan K K</title>
      <link>https://forem.com/srinivasankk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/srinivasankk"/>
    <language>en</language>
    <item>
      <title>My Top 5 Favorite Things from JavaScript ES2020</title>
      <dc:creator>Srinivasan K K</dc:creator>
      <pubDate>Thu, 09 Apr 2020 10:37:00 +0000</pubDate>
      <link>https://forem.com/srinivasankk/my-top-5-favorite-things-from-javascript-es2020-43d1</link>
      <guid>https://forem.com/srinivasankk/my-top-5-favorite-things-from-javascript-es2020-43d1</guid>
      <description>&lt;p&gt;Being a JavaScript developer, knowing the ECMAScript standards is the essential one.&lt;/p&gt;

&lt;p&gt;So, I would like to share my top 5 favorite things from JavaScript &lt;code&gt;ES2020&lt;/code&gt; which are all finalized proposals (&lt;code&gt;stage 4&lt;/code&gt;).&lt;/p&gt;

&lt;h1&gt;
  
  
  Top 5 Favorite Things From JavaScript ES2020
&lt;/h1&gt;

&lt;h3&gt;
  
  
  1. Nullish Operator (&lt;code&gt;??&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Before this introduced, we have been using &lt;code&gt;||&lt;/code&gt; OR operator. But &lt;code&gt;??&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; basically serves a different purpose.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;||&lt;/code&gt; is to check &lt;code&gt;falsy&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy"&gt;values&lt;/a&gt; whereas &lt;code&gt;??&lt;/code&gt; operator is to check both &lt;code&gt;NULL&lt;/code&gt; or &lt;code&gt;Undefined&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = { name: 'John' };
console.log(user.name ?? 'Not Exists.');
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Optional Chaining (&lt;code&gt;?.&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Before this, we have been using &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; AND operator to check whether left-hand side expression returns true, then the right-hand side expression would be evaluated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = { name: 'John' };
console.log(user?.name);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Dynamically Importing JS Module
&lt;/h3&gt;

&lt;p&gt;We could lazy load the JS module at runtime by using this option,&lt;br&gt;
&lt;code&gt;import(&amp;lt;module_file_name&amp;gt;)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async loadUser() {
  const user = await import(`./user.js`);
  console.log(user.getName());
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Accessing Global Context
&lt;/h3&gt;

&lt;p&gt;We use a certain keyword to access the &lt;code&gt;global&lt;/code&gt; context but it differs for each environment. For instance, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;window&lt;/code&gt; is the keyword for &lt;code&gt;browser&lt;/code&gt; environment,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;global&lt;/code&gt; is the keyword for &lt;code&gt;Node.js&lt;/code&gt; environment,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;self&lt;/code&gt; is the keyword for &lt;code&gt;Web/service workers&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;globalThis&lt;/code&gt; is the new keyword that solves the above environment context issue.&lt;/p&gt;

&lt;p&gt;As a web developer, We often stick to &lt;code&gt;write once run it anywhere&lt;/code&gt; principle. In this fashion, this new addition would help us a lot.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Promise.allSettled (&lt;code&gt;Promise.allSettled([inputs])&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;As a web developer, invoking multiple HTTP requests simultaneously is the usual thing.&lt;br&gt;
&lt;code&gt;Promise.allSettled([])&lt;/code&gt;, this one will be settled down when all the inputs are either resolved/rejected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getUser = () =&amp;gt; Promise.resolve({ name: 'John' });
const getUserRights = () =&amp;gt; Promise.reject(new Error(`Unauthorized Access...`));
const getUsersCount = () =&amp;gt; Promise.resolve({ total: 5000 });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's say we have 3 promise calls which we are going to invoke parallelly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Promise.allSettled([getUser(), getUserRights(), getUsersCount()])
       .then(([user, rights, count]) =&amp;gt; {
           if(user.status === 'resolved') { console.log(user.value); }
        })
       .catch(console.error);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We have different options available to invoke multiple &lt;code&gt;Promise&lt;/code&gt; calls at a time, &lt;code&gt;Promise.all([])&lt;/code&gt; and &lt;code&gt;Promise.race([])&lt;/code&gt;. But those two Promise objects differ based on the use case.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.all([x, y, z])&lt;/code&gt; will invoke all the given Promises parallelly but if anyone is failed then this operation would end up in &lt;code&gt;catch&lt;/code&gt; block of &lt;code&gt;Promise.all([])&lt;/code&gt;. But the resolved input promise would be ignored.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.race([x, y, z])&lt;/code&gt;, this output will be resolved as soon as one of the input promise is resolved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; If you're coming from C# background you have already familiar with &lt;code&gt;??&lt;/code&gt; and &lt;code&gt;?.&lt;/code&gt; operators.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Creating Dynamic Rows &amp; Columns with CSS-Grid</title>
      <dc:creator>Srinivasan K K</dc:creator>
      <pubDate>Wed, 18 Mar 2020 05:25:31 +0000</pubDate>
      <link>https://forem.com/srinivasankk/creating-dynamic-rows-columns-with-css-grid-55md</link>
      <guid>https://forem.com/srinivasankk/creating-dynamic-rows-columns-with-css-grid-55md</guid>
      <description>&lt;p&gt;In this blog post, I would like to share on &lt;strong&gt;how to create dynamic rows and columns with CSS-Grid&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I have created the &lt;strong&gt;Scheduler UI&lt;/strong&gt; template markup to demonstrate further.&lt;/p&gt;

&lt;h2&gt;
  
  
  IDEA
&lt;/h2&gt;

&lt;p&gt;Only learning doesn’t serve any purpose instead building an application will.&lt;/p&gt;

&lt;p&gt;This app comprises Scheduler option input and based on the input will create a container with grid-cell for showing the day but dynamically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic CSS-Grid Columns &amp;amp; Rows
&lt;/h2&gt;

&lt;p&gt;I cover the bare essential piece from the below code.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;  
  &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-options"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"javascript:void(0)"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"optn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;daily&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"javascript:void(0)"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"optn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;weekly&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"javascript:void(0)"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"optn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;monthly&lt;span class="nt"&gt;&amp;lt;/a&amp;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="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"month-name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"slots"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-grid daily"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-grid weekly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-grid monthly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;javascript:void(0)&lt;/code&gt; will restrict redirecting URL.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.scheduler-grid&lt;/code&gt; element acts as a &lt;em&gt;CSS-Grid&lt;/em&gt; container and based on the &lt;em&gt;scheduler-options&lt;/em&gt; input each grid container will be filled with grid cells.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nc"&gt;.scheduler-grid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&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;code&gt;grid-auto-rows&lt;/code&gt; &lt;code&gt;grid-template-columns&lt;/code&gt; &lt;code&gt;repeat&lt;/code&gt; &lt;code&gt;minmax&lt;/code&gt; and &lt;code&gt;auto-fill&lt;/code&gt; are the CSS-Grid configuration for dynamic creation of grid-cells.&lt;/p&gt;

&lt;p&gt;The CSS &lt;code&gt;repeat&lt;/code&gt; function will create the grid-cells based on the given min and max width of each cell using &lt;code&gt;minmax&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;important point&lt;/strong&gt; we should get it here is that, if we use both &lt;code&gt;grid-template-rows&lt;/code&gt; and &lt;code&gt;grid-template-columns&lt;/code&gt; for dynamic creation then rows will get cut at the end of the viewport.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-1.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%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-1.png" alt="BrokeRow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hence, &lt;strong&gt;to avoid this&lt;/strong&gt; we should set the row height for the dynamically creating rows with the help of &lt;strong&gt;grid-auto-rows&lt;/strong&gt; property.&lt;/p&gt;

&lt;p&gt;After all this, we would end up with the below expected result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-6.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%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-6.png" alt="Scheduler_UI"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>design</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to create Reusable Date Utility in JavaScript</title>
      <dc:creator>Srinivasan K K</dc:creator>
      <pubDate>Tue, 03 Mar 2020 10:06:19 +0000</pubDate>
      <link>https://forem.com/srinivasankk/find-a-specific-date-from-today-s-date-in-javascript-47a3</link>
      <guid>https://forem.com/srinivasankk/find-a-specific-date-from-today-s-date-in-javascript-47a3</guid>
      <description>&lt;p&gt;Every one of us faced a hard time when comes to work on Date with JavaScript. Then I thought of creating the simple utility to get familiar with &lt;code&gt;JavaScript Date API&lt;/code&gt;,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;to find a specific date from the current date in JavaScript.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After wrote this utility, I wanted to share the same with other peers so ended up writing this article.&lt;/p&gt;

&lt;h1&gt;
  
  
  Date Constructor
&lt;/h1&gt;

&lt;p&gt;To get the current date we have a Date API from JavaScript, &lt;code&gt;new Date();&lt;/code&gt;&lt;br&gt;
The same can be retrieved by passing &lt;code&gt;date string&lt;/code&gt; as an input to the new Date();&lt;/p&gt;

&lt;p&gt;As most of us haven’t exposed to &lt;code&gt;one more way&lt;/code&gt; of getting date value,&lt;code&gt;new Date(year, month, date, hh, mm, ss);&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Find a specific date from today's date in JavaScript
&lt;/h1&gt;

&lt;p&gt;To solve any kind of problem first, we need to list down the required inputs and draw the pseudo-code if required.&lt;/p&gt;

&lt;p&gt;In short, we require the following inputs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logic to derive the previous date,&lt;/li&gt;
&lt;li&gt;Day count of the previous month,&lt;/li&gt;
&lt;li&gt;Previous Year&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I created one reusable function named &lt;code&gt;getDateInfo&lt;/code&gt; which gives us all the information about today's date except time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getDateInfo() {
  // Date Calculation
  const todayDate = new Date();
  const months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
  const dayCount = {
    'January': 31, 
    'February': (todayDate.getFullYear()%4 === 0) ? 29 : 28,
    'March': 31,'April': 30,'May':31,'June':30,'July':31,'August':31,'September':30,'October':31,'November':30,'December':31
  }
  const days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  const currentMonth = months[todayDate.getMonth()];
  const currentYear = todayDate.getFullYear();
  const currentDate = todayDate.getDate();
  const currentDay = days[todayDate.getDay()];
  return {
    todayDate, months, dayCount, days, currentMonth, currentYear, currentDate, currentDay
  };
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Utility
&lt;/h1&gt;

&lt;p&gt;I shared the logic part also to give you hindsight and you will find it below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findDateFromToday({ howManyDates = 0, type = 'past' }){
  try {
    const { todayDate, months, dayCount, days, currentMonth, currentYear, currentDate, currentDay} = getDateInfo();
    if(type === 'past') {
      const resultDate = currentDate - howManyDates;
      if(resultDate === 0) {
        // Starting date of the current month
        return new Date(currentYear, todayDate.getMonth(),0,0,0);
      } else if(resultDate &amp;gt; 0) {
        // resultDate of the month
        return new Date(currentYear, todayDate.getMonth(), resultDate, 0,0,0);
      } else {
        let prevMonth;
        let prevYear;
        // if negative, then (previous month day count - (negative resultDate))
        if(todayDate.getMonth() !== 0) {
          prevMonth = todayDate.getMonth() - 1;
          const prevDate = dayCount[months[prevMonth]];
          return new Date(currentYear, prevMonth, prevDate +resultDate,0,0,0);
        } else {
          // previous year
          prevYear = currentYear - 1;
          // previous month
          prevMonth = 11; // december
          const prevDate = dayCount[months[prevMonth]];
          return new Date(prevYear, prevMonth, prevDate + (resultDate),0,0,0);
        }
      }
    }
  } catch(error) {
    return error;
  }  
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;howManyDates&lt;/code&gt; parameter is for how many dates from today.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;type&lt;/code&gt; parameter is for identifying a specific date that would fall on either past or future. Here only considered for finding the previous date value. If you're well curious enough then please go ahead do yourself for the future date.&lt;/p&gt;

&lt;h1&gt;
  
  
  Logic - To find the previous date
&lt;/h1&gt;

&lt;p&gt;I sorted out this utility based on the below logic, You can also add if more meaningful for making reusable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Step 1: Subtract today date from &lt;code&gt;howManyDates&lt;/code&gt;count&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 2: If the subtracted value is 0 then the previous month's last date.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 3: If the subtracted value is &amp;gt; 0, then the result date of the current month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 4: If the subtracted value is &amp;lt; 0, then will derive by using the previous month and previous year as below code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it. You can also share your opinion on improving further on this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Originally Published at &lt;a href="https://srinivasankk.com/find-specific-date-from-todays-date-in-javascript/"&gt;Personal Blog&lt;/a&gt;
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>productivity</category>
      <category>functional</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
