<?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: Aditya Khare</title>
    <description>The latest articles on DEV Community by Aditya Khare (@thedevguy).</description>
    <link>https://dev.to/thedevguy</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%2F814394%2Fa8eeabe4-d830-4217-b826-3e16303deb61.jpeg</url>
      <title>DEV Community: Aditya Khare</title>
      <link>https://dev.to/thedevguy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thedevguy"/>
    <language>en</language>
    <item>
      <title>4 Most Useful features of the Window Object</title>
      <dc:creator>Aditya Khare</dc:creator>
      <pubDate>Thu, 24 Mar 2022 18:19:13 +0000</pubDate>
      <link>https://dev.to/thedevguy/5-most-useful-features-of-the-window-object-2728</link>
      <guid>https://dev.to/thedevguy/5-most-useful-features-of-the-window-object-2728</guid>
      <description>&lt;p&gt;One of the main elements of JavaScript DOM is the global Window Object.&lt;br&gt;
There are many useful methods and objects it provides, but some are just more frequently used than others, which is the reason of me writing this article to introduce you to the features that I found most Useful for me. &lt;br&gt;
So Let's Get Started :&lt;/p&gt;
&lt;h2&gt;
  
  
  1. setTimeout() :
&lt;/h2&gt;

&lt;p&gt;The first method that I want to talk about is &lt;code&gt;setTimeout()&lt;/code&gt;.&lt;br&gt;
What this method does is basically call a certain function once after a certain time which you provide.&lt;br&gt;
The method takes two arguments, A callback function and time (in milliseconds) after which you want that function to run.&lt;br&gt;
Imagine if you have to display a success or error modal after submitting a Form after a certain period or if you are just working on a Project Locally and want to imitate a fetch request from an API. Well, the &lt;strong&gt;setTimeout()&lt;/strong&gt; method is the way to go.&lt;/p&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%2Fkl3cpvww2syaqutovlxm.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%2Fkl3cpvww2syaqutovlxm.png" alt="setTimeout in Action" width="800" height="339"&gt;&lt;/a&gt;&lt;br&gt;
In the Example Above we ask if the user wants a custom theme for the website 5 seconds after the page is loaded.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. setInterval() :
&lt;/h2&gt;

&lt;p&gt;Many times, we want to run a function multiple times after certain intervals. &lt;code&gt;setInterval()&lt;/code&gt; is the solution for such use cases.&lt;br&gt;
The syntax of &lt;em&gt;setInterval()&lt;/em&gt; is similar to &lt;em&gt;setTimeout()&lt;/em&gt; as it also takes the function which you want to run and the interval in which you want the given function to run each time.&lt;br&gt;
But what if you want to stop the function after certain intervals.&lt;br&gt;
Well , there's also a method for just that. The &lt;code&gt;clearInterval()&lt;/code&gt; takes the timerId or basically a variable in which the value of &lt;code&gt;setInterval()&lt;/code&gt; is stored and stops/clears the function inside setInterval().&lt;/p&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%2Fdv44f3mv4t7sg848kc18.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%2Fdv44f3mv4t7sg848kc18.png" alt="setInterval example" width="800" height="565"&gt;&lt;/a&gt;&lt;br&gt;
In the Above Example, the setInterval method updates our UI each second with an icremental value, thus forming a Timer.&lt;br&gt;
&lt;strong&gt;NOTE :&lt;/strong&gt;There's also a Catch with &lt;code&gt;setInterval()&lt;/code&gt;, the function you call inside this can also take up time to execute, hence the interval you passed with the method can take up more time.&lt;br&gt;
For this purpose, if you want to be precise with your delay at regular intervals. I'll Recommend using a nested &lt;code&gt;setTimeout()&lt;/code&gt; method instead.&lt;br&gt;
I could try to explain more about the why and how of both &lt;code&gt;setInterval()&lt;/code&gt; and a nested &lt;code&gt;setTimeout()&lt;/code&gt; in detail, but I think &lt;a href="https://javascript.info/settimeout-setinterval#nested-settimeout"&gt;this article here&lt;/a&gt; does the job very well.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. scrollTo()
&lt;/h2&gt;

&lt;p&gt;One of the most Used window method, No website today is complete without a Back to Top button. I mean who doesn't love one such button at the footer of a website which when clicked saves you the hazard to use the Scrollbar to get back to the top of the Page. Also it makes navigating through different sections of your website easy and neat which also increases the User-Experience. With &lt;code&gt;scrollTo()&lt;/code&gt;, you can implement this functionality with a single line. &lt;br&gt;
The method takes two arguments, the X and Y (horizontal and vertical) co-ordinates of where you want to scroll to on the page. &lt;br&gt;
the value cannot be negative.&lt;br&gt;
Use this with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html {
scroll-behavior: smooth;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in your CSS for enabling smooth scrolling and you are good to go.&lt;/p&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%2Fufhqocccr9x6qwgf2gbw.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%2Fufhqocccr9x6qwgf2gbw.png" alt="scrollTo example" width="620" height="486"&gt;&lt;/a&gt;&lt;br&gt;
The above example shows a button which takes the user to the top of the Page when clicked.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Local Storage
&lt;/h2&gt;

&lt;p&gt;This Last one is not a method but an Object with very useful methods.&lt;br&gt;
How many times have you got your UI changes destroyed (removed) after reloading the Page. All your data with your hardwork to make the app work, Gone.&lt;br&gt;
Therefore if you want to persist the changes you made to your website even after you reload the website, you'll need this object methods. Like all Objects &lt;em&gt;LocalStorage&lt;/em&gt; stores key value pairs and almost all object methods work on it like any other plain Object.&lt;br&gt;
It mainly uses two methods which are &lt;code&gt;LocalStorage.setItem()&lt;/code&gt; and &lt;code&gt;LocalStorage.setItem()&lt;/code&gt; to save and retrieve a value from the &lt;strong&gt;LocalStorage&lt;/strong&gt; Object. The Earlier takes key and value as arguments while the later only takes key. The keys and values stored in the LocalStorage object can only be strings. So if you want to store objects within the LocalStorage you can use the &lt;strong&gt;JSON.stringify()&lt;/strong&gt; method like below :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
localStorage.user = JSON.stringify({name: "John"});

// sometime later
let user = JSON.parse( localStorage.user );
console.log( user.name ); // John
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's also a &lt;code&gt;LocalStorage.removeItem(key)&lt;/code&gt; which removes the item from the storage by it's key.&lt;br&gt;
The best Use Case for using LocalStorage in Authenticating User on the Frontend. You could just save an Authorization Token sent from an API to the LocalStorage and Retrieve it later from the minimum 2MB storage space that all modern browsers provide today.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Window&lt;/strong&gt; Object is like a Magic hat which has a lot of other tricks to offer. We'll talk about what other magical things it's hiding in a future Article.&lt;/p&gt;

&lt;p&gt;Till then,&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Getting started with CSS Custom Properties</title>
      <dc:creator>Aditya Khare</dc:creator>
      <pubDate>Sun, 13 Feb 2022 04:54:40 +0000</pubDate>
      <link>https://dev.to/thedevguy/getting-started-with-css-custom-properties-401g</link>
      <guid>https://dev.to/thedevguy/getting-started-with-css-custom-properties-401g</guid>
      <description>&lt;p&gt;Do you know that you can use Variables in Vanilla CSS without any preprocessors like SASS or LESS&lt;br&gt;
Let's Find out How...&lt;/p&gt;

&lt;p&gt;But first the question arises that Why should you even use these Custom properties when You have Preprocessors.&lt;br&gt;
Well,&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use CSS Custom Properties over SASS variables
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Learning SASS for only using Variables is much of an effort, so why do it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No need for a compiler to convert your SASS files into normal CSS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Native, therefore fast and browser compatible.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, let's understand What the heck are these CSS Custom Properties.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Custom Properties
&lt;/h2&gt;

&lt;p&gt;If you ever used a Programming language before, you know what a variable is.&lt;br&gt;
If not, A variable is something that is defined once, usually at the top of the code, and then can be referenced later anywhere in the code.&lt;/p&gt;

&lt;p&gt;So Basically, the custom properties are the variables of CSS which minimizes code repetition and saves time. The custom properties are very helpful in large projects.&lt;/p&gt;

&lt;p&gt;In normal CSS you have to redefine a property like color or font repetitively for different elements and it is a hazard.&lt;/p&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%2Fnddmv106hfwbgvpyzc3k.jpeg" 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%2Fnddmv106hfwbgvpyzc3k.jpeg" alt="Code Snippet" width="800" height="933"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well not anymore, &lt;br&gt;
Define once, use anywhere from now on.&lt;br&gt;
A custom property is written with a preceding &lt;code&gt;--&lt;/code&gt; sign before its name with no spaces and called(used) with the &lt;code&gt;var()&lt;/code&gt; keyword.&lt;/p&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%2Fx8ep9wxv55a9gnk8rcqe.jpeg" 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%2Fx8ep9wxv55a9gnk8rcqe.jpeg" alt="Code Snippet" width="800" height="1114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of CSS Variables
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility:&lt;/strong&gt;
One great benefit of Custom properties is that you can structure and combine different variables for more flexibility. 
Any value you can think of can be converted into a variable.&lt;/li&gt;
&lt;/ol&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%2Fvu0z1hax6ze5oj3h5q54.jpeg" 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%2Fvu0z1hax6ze5oj3h5q54.jpeg" alt="Code Snippet" width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Redefining Your Variables:&lt;/strong&gt;
An Environment is like a world within itself for a code block.
The Code within a environment doesn't care anything about anything outside it's environment and obeys the rules of it's own Environment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With CSS variables, You can also redefine or change the value of a custom property with a new value within a specific element and it will work with that value in its local environment instead of the globally defined custom property.&lt;/p&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%2Fkg9l5tfnvs8ywosyf9wt.jpeg" 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%2Fkg9l5tfnvs8ywosyf9wt.jpeg" alt="Code Snippet" width="800" height="682"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Using &lt;code&gt;calc()&lt;/code&gt; function with your variables:&lt;/strong&gt;
The &lt;code&gt;calc()&lt;/code&gt; function can perform basic mathematical operations in CSS.
Make your whole layout responsive by using it with predefined custom properties which helps in structuring the sizes of your elements.
&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%2Fmn8fxj6cvwlvzenb5byu.jpg" alt="Code Snippet" width="679" height="568"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can do so much more with custom properties. &lt;br&gt;
Comment how you utilize and make the best use of CSS custom properties.&lt;br&gt;
This post is a result of my Twitter Thread on the Custom Properties, if you like to see more follow me on my twitter handle.&lt;/p&gt;

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