<?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: kumar_lav</title>
    <description>The latest articles on DEV Community by kumar_lav (@lav-01).</description>
    <link>https://dev.to/lav-01</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%2F1237514%2Fef025675-de38-45f5-96e6-548e621bf84d.jpg</url>
      <title>DEV Community: kumar_lav</title>
      <link>https://dev.to/lav-01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lav-01"/>
    <language>en</language>
    <item>
      <title>Implementing AutoLogout Feature in Class Components(React-JS)</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Tue, 09 Apr 2024 13:31:32 +0000</pubDate>
      <link>https://dev.to/lav-01/implementing-autologout-feature-in-class-componentsreact-js-do5</link>
      <guid>https://dev.to/lav-01/implementing-autologout-feature-in-class-componentsreact-js-do5</guid>
      <description>&lt;p&gt;We have noticed that financial applications, log automatically after a certain time of inactivity. This feature is particularly important when dealing with sensitive web applications like financial apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  NOTE:
&lt;/h2&gt;

&lt;p&gt;In MainDashboardEntry (this should be the base entry file for all component routes),&lt;/p&gt;

&lt;h2&gt;
  
  
  talking about the solution
&lt;/h2&gt;

&lt;p&gt;When the component mounts, add listeners to the window that listens to the events.&lt;br&gt;
Create a function that logs out a user after 10 seconds using set Timeout.&lt;br&gt;
Each time any of the events is triggered, i.e. mouse move, click, scroll, keypress, etc., the timer to log out the user after 10 seconds of inactivity resets.&lt;br&gt;
However, if none of the events is triggered within 10 seconds, that is app is inactive, the app automatically logs out.&lt;/p&gt;

&lt;p&gt;mentioning are some points below these user events to guarantee user activity on the application&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let timer;&lt;br&gt;
const events = [&lt;br&gt;
  "load",&lt;br&gt;
  "mousemove",&lt;br&gt;
  "mousedown",&lt;br&gt;
  "Click",&lt;br&gt;
  "scroll",&lt;br&gt;
  "keypress",&lt;br&gt;
];&lt;/code&gt; &lt;br&gt;
Note: these variables should be&lt;/p&gt;

&lt;p&gt;`class IdleTimerContainer extends React.Component {&lt;br&gt;
constructor(props: any) {&lt;br&gt;
    super(props);&lt;br&gt;
}&lt;br&gt;
handleLogoutTimer() {&lt;br&gt;
    timer = setTimeout(() =&amp;gt; {&lt;br&gt;
      // clears any pending timer.&lt;br&gt;
      this.resetTimer();&lt;br&gt;
      // Listener clean up. Removes the existing event listener from the window&lt;br&gt;
      Object.values(events).forEach((item) =&amp;gt; {&lt;br&gt;
        window.removeEventListener(item, this.resetTimer);&lt;br&gt;
        console.log("2 second")&lt;br&gt;
      });&lt;br&gt;
      // logs out user&lt;br&gt;
      this.logoutAction();&lt;br&gt;
    }, 2000); // 10000ms = 10secs. You can change the time.&lt;br&gt;
  };&lt;br&gt;
  resetTimer (){&lt;br&gt;
    if (timer) clearTimeout(timer);&lt;br&gt;
  };&lt;br&gt;
  componentDidMount(): void {&lt;br&gt;
    Object.values(events).forEach((item) =&amp;gt; {&lt;br&gt;
      window.addEventListener(item, () =&amp;gt; {&lt;br&gt;
        this.resetTimer();&lt;br&gt;
        this.handleLogoutTimer();&lt;br&gt;
      });&lt;br&gt;
    });&lt;br&gt;
  }&lt;br&gt;
  logoutAction = () =&amp;gt; {&lt;br&gt;
    localStorage.clear();&lt;br&gt;
    window.location.pathname = "/"; // login page while the user is an inactive redirect to login page we can set the path accordingly &lt;br&gt;
  };&lt;/p&gt;

&lt;p&gt;export default IdleTimerContainer;&lt;/p&gt;

&lt;p&gt;//If you are using this functionality we can use the useEffect&lt;/p&gt;

&lt;p&gt;`&lt;/p&gt;

</description>
      <category>react</category>
      <category>autologout</category>
      <category>javascript</category>
      <category>webapplication</category>
    </item>
    <item>
      <title>All of the following values are falsy</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sun, 10 Mar 2024 16:19:51 +0000</pubDate>
      <link>https://dev.to/lav-01/all-of-the-following-values-are-falsy-1ceo</link>
      <guid>https://dev.to/lav-01/all-of-the-following-values-are-falsy-1ceo</guid>
      <description>&lt;p&gt;&lt;code&gt;false&lt;br&gt;
null&lt;br&gt;
undefined&lt;br&gt;
0&lt;br&gt;
-0&lt;br&gt;
NaN&lt;br&gt;
An empty string ('')&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Here's a list of numbers. What do you think? Which of them become true and which become false?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Boolean(100));
console.log(Boolean(1));
console.log(Boolean(0));
console.log(Boolean(-5));
let name = true
name = false

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

&lt;/div&gt;



&lt;p&gt;Example &lt;br&gt;
true&lt;br&gt;
true&lt;br&gt;
false&lt;br&gt;
true&lt;br&gt;
false&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Finding Your Way With .Map()</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Mon, 04 Mar 2024 13:05:27 +0000</pubDate>
      <link>https://dev.to/lav-01/finding-your-way-with-map-27oo</link>
      <guid>https://dev.to/lav-01/finding-your-way-with-map-27oo</guid>
      <description>&lt;p&gt;The map method allows us to transform each element of an array, without affecting the original array. It’s considered a higher-order function and a functional programming technique because it takes a function as an argument and we are performing computation without mutating the state of our application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Map is a property that is inherited from the array prototype. Prototypes provide built-in-methods that objects come with (arrays are special types of objects in the eyes of JavaScript). While map may be a little more foreign, this prototype is no different than, for example, the Array.length prototype. These are simply methods that are baked into JavaScript. Array prototypes can be added and mutated by: Array.prototype. = ...&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  So what does .map() do?
&lt;/h3&gt;

&lt;p&gt;Let’s say you have an array of temperatures in Celsius that you want to convert to Fahrenheit.&lt;/p&gt;

&lt;p&gt;There are several ways to solve this problem. One way may be to write a for loop to create an array of Fahrenheit temperatures from the given Celsius temperatures.&lt;/p&gt;

&lt;p&gt;With the for loop we might write:&lt;/p&gt;

&lt;p&gt;const celciusTemps = [22, 36, 71, 54];&lt;br&gt;
const getFahrenheitTemps = (function(temp) {&lt;br&gt;
   const fahrenheitTemps = [];&lt;br&gt;
   for (let i = 0; i &amp;lt; celciusTemps.length; i += 1) {&lt;br&gt;
      temp = celciusTemps[i] * (9/5) + 32&lt;br&gt;
      fahrenheitTemps.push(temp);&lt;br&gt;
   }&lt;br&gt;
   console.log(fahrenheitTemps); [71.6, 96.8, 159.8, 129.2&lt;br&gt;
})();&lt;/p&gt;
&lt;h2&gt;
  
  
  **So how does a map work?
&lt;/h2&gt;

&lt;p&gt;**&lt;br&gt;
Map takes a function and applies that function to each element in the array. We could write a map a bit more verbose with ES5 to see this a bit more clearly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fahrenheitTemps = celciusTemps

   .map(function(elementOfArray) {
      return elementOfArray * (9/5) + 32;
   });
console.log(fahrenheitTemps); // [71.6, 96.8, 159.8, 129.2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const people = [
   {name: Steve, age: 32},
   {name: Mary, age: 28},
   {name: Bill, age: 41},
];
const getNames = (function(person) {
   const names = [];
   for (let i = 0; i &amp;lt; people.length; i += 1) {
      name = people[i].name;
      names.push(name);
   }
   console.log(names); // [Steve, Mary, Bill];
})();
With map:

const names = people.map(e =&amp;gt; e.name);
console.log(names) // [Steve, Mary, Bill];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you want to learn more deeply, reference this URL&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/finding-your-way-with-map-aecb8ca038f6"&gt;https://www.freecodecamp.org/news/finding-your-way-with-map-aecb8ca038f6&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>map</category>
    </item>
    <item>
      <title>What is a promise</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sun, 03 Mar 2024 16:17:17 +0000</pubDate>
      <link>https://dev.to/lav-01/what-is-a-promise-1g77</link>
      <guid>https://dev.to/lav-01/what-is-a-promise-1g77</guid>
      <description>&lt;h2&gt;
  
  
  **The syntax of Promise creation looks like below,
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promise = new Promise(function (resolve, reject) {
  // promise description
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The usage of a promise would be as below,
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`const promise = new Promise(
  (resolve) =&amp;gt; {
    setTimeout(() =&amp;gt; {
      resolve("I'm a Promise!");
    }, 5000);
  },
  (reject) =&amp;gt; {}
);

promise.then((value) =&amp;gt; console.log(value));`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The action flow of a promise will be as below,
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fne4f3eimp1d7pdxvexo1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fne4f3eimp1d7pdxvexo1.png" alt="Image description" width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What is the currying function</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sun, 03 Mar 2024 16:12:37 +0000</pubDate>
      <link>https://dev.to/lav-01/what-is-the-currying-function-3kpi</link>
      <guid>https://dev.to/lav-01/what-is-the-currying-function-3kpi</guid>
      <description>&lt;p&gt;Currying is the process of taking a function with multiple arguments and turning it into a sequence of functions each with only a single argument. Currying is named after a mathematician Haskell Curry. By applying currying, an n-ary function turns into a unary function.&lt;/p&gt;

&lt;p&gt;Let's take an example of n-ary function and how it turns into a currying function,&lt;/p&gt;

&lt;p&gt;const multiArgFunction = (a, b, c) =&amp;gt; a + b + c;&lt;br&gt;
console.log(multiArgFunction(1, 2, 3)); // 6&lt;/p&gt;

&lt;p&gt;const curryUnaryFunction = (a) =&amp;gt; (b) =&amp;gt; (c) =&amp;gt; a + b + c;&lt;br&gt;
curryUnaryFunction(1); // returns a function: b =&amp;gt; c =&amp;gt;  1 + b + c&lt;br&gt;
curryUnaryFunction(1)(2); // returns a function: c =&amp;gt; 3 + c&lt;br&gt;
curryUnaryFunction(1)(2)(3); // returns the number 6&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is a higher order function</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sun, 03 Mar 2024 16:11:46 +0000</pubDate>
      <link>https://dev.to/lav-01/what-is-a-higher-order-function-6ai</link>
      <guid>https://dev.to/lav-01/what-is-a-higher-order-function-6ai</guid>
      <description>&lt;p&gt;A higher-order function is a function that accepts another function as an argument or returns a function as a return value or both.&lt;/p&gt;

&lt;p&gt;const firstOrderFunc = () =&amp;gt;&lt;br&gt;
  console.log("Hello, I am a First order function");&lt;br&gt;
const higherOrder = (ReturnFirstOrderFunc) =&amp;gt; ReturnFirstOrderFunc();&lt;br&gt;
higherOrder(firstOrderFunc);&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is a first order function?</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sun, 03 Mar 2024 16:10:41 +0000</pubDate>
      <link>https://dev.to/lav-01/what-is-a-first-order-function-4ap</link>
      <guid>https://dev.to/lav-01/what-is-a-first-order-function-4ap</guid>
      <description>&lt;p&gt;A first-order function is a function that doesn’t accept another function as an argument and doesn’t return a function as its return value.&lt;/p&gt;

&lt;p&gt;const firstOrder = () =&amp;gt; console.log("I am a first order function!");&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is the difference between == and === operators</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sat, 02 Mar 2024 14:58:57 +0000</pubDate>
      <link>https://dev.to/lav-01/what-is-the-difference-between-and-operators-1okd</link>
      <guid>https://dev.to/lav-01/what-is-the-difference-between-and-operators-1okd</guid>
      <description>&lt;p&gt;JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,&lt;/p&gt;

&lt;p&gt;Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.&lt;br&gt;
Two numbers are strictly equal when they are numerically equal, i.e., having the same number value. There are two special cases in this,&lt;br&gt;
NaN is not equal to anything, including NaN.&lt;br&gt;
Positive and negative zeros are equal to one another.&lt;br&gt;
Two Boolean operands are strictly equal if both are true or both are false.&lt;br&gt;
Two objects are strictly equal if they refer to the same Object.&lt;br&gt;
Null and Undefined types are not equal with ===, but equal with == . i.e, null===undefined --&amp;gt; false, but null==undefined --&amp;gt; true&lt;br&gt;
Some of the example which covers the above cases:&lt;/p&gt;

&lt;p&gt;0 == false   // true&lt;br&gt;
0 === false  // false&lt;br&gt;
1 == "1"     // true&lt;br&gt;
1 === "1"    // false&lt;br&gt;
null == undefined // true&lt;br&gt;
null === undefined // false&lt;br&gt;
'0' == false // true&lt;br&gt;
'0' === false // false&lt;br&gt;
NaN == NaN or NaN === NaN // false&lt;br&gt;
[]==[] or []===[] //false, refer different objects in memory&lt;br&gt;
{}=={} or {}==={} //false, refer different objects in memory&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Singleton pattern:</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sat, 02 Mar 2024 14:57:03 +0000</pubDate>
      <link>https://dev.to/lav-01/singleton-pattern-36nk</link>
      <guid>https://dev.to/lav-01/singleton-pattern-36nk</guid>
      <description>&lt;p&gt;A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance. This way one can ensure that they don't accidentally create multiple instances.&lt;/p&gt;

&lt;p&gt;var object = new (function () {&lt;br&gt;
  this.name = "lavk";&lt;br&gt;
})()&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>the git repository for interview preparation</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sat, 02 Mar 2024 14:55:10 +0000</pubDate>
      <link>https://dev.to/lav-01/interview-preparation-referencing-the-github-repo-39en</link>
      <guid>https://dev.to/lav-01/interview-preparation-referencing-the-github-repo-39en</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://github.com/sudheerj/javascript-interview-questions

https://github.com/lydiahallie/javascript-questions

https://github.com/airbnb/javascript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>github</category>
      <category>git</category>
    </item>
    <item>
      <title>What is Hoisting?</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sat, 02 Mar 2024 14:51:22 +0000</pubDate>
      <link>https://dev.to/lav-01/what-is-hoisting-2oki</link>
      <guid>https://dev.to/lav-01/what-is-hoisting-2oki</guid>
      <description>&lt;p&gt;Hoisting is a JavaScript mechanism where variables, function declarations, and classes are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialization. Let's take a simple example of variable hoisting,&lt;/p&gt;

&lt;p&gt;console.log(message); //output : undefined&lt;br&gt;
var message = "The variable Has been hoisted";&lt;br&gt;
The above code looks like as below to the interpreter,&lt;/p&gt;

&lt;p&gt;var message;&lt;br&gt;
console.log(message);&lt;br&gt;
message = "The variable Has been hoisted";&lt;br&gt;
In the same fashion, function declarations are hoisted too&lt;/p&gt;

&lt;p&gt;message("Good morning"); //Good morning&lt;/p&gt;

&lt;p&gt;function message(name) {&lt;br&gt;
  console.log(name);&lt;br&gt;
}&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is the purpose of the let keyword?</title>
      <dc:creator>kumar_lav</dc:creator>
      <pubDate>Sat, 02 Mar 2024 14:50:13 +0000</pubDate>
      <link>https://dev.to/lav-01/what-is-the-purpose-of-the-let-keyword-1l17</link>
      <guid>https://dev.to/lav-01/what-is-the-purpose-of-the-let-keyword-1l17</guid>
      <description>&lt;p&gt;The let statement declares a block scope local variable. Hence the variables defined with let keyword are limited in scope to the block, statement, or expression on which it is used. Whereas variables declared with the var keyword are used to define a variable globally, or locally to an entire function regardless of block scope.&lt;/p&gt;

&lt;p&gt;Let's take an example to demonstrate the usage,&lt;/p&gt;

&lt;p&gt;let counter = 30;&lt;br&gt;
if (counter === 30) {&lt;br&gt;
  let counter = 31;&lt;br&gt;
  console.log(counter); // 31&lt;br&gt;
}&lt;br&gt;
console.log(counter); // 30 (because the variable in if block won't exist here)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
