<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ Harshalini Pandhare's Blog]]></title><description><![CDATA[ Harshalini Pandhare's Blog]]></description><link>https://harshalini-pandhare.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 14:57:14 GMT</lastBuildDate><atom:link href="https://harshalini-pandhare.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[UseState Hook]]></title><description><![CDATA[What are hooks?
Hooks are basically meant to maintain state in ReactJS without writing a class component. 
Hooks are a new addition in React 16.8. There are various hooks in react for different purposes. Let us see what is a useState hook.  
The useS...]]></description><link>https://harshalini-pandhare.hashnode.dev/usestate-hook</link><guid isPermaLink="true">https://harshalini-pandhare.hashnode.dev/usestate-hook</guid><category><![CDATA[React]]></category><category><![CDATA[hooks]]></category><category><![CDATA[useState]]></category><category><![CDATA[coding]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Harshalini Pandhare]]></dc:creator><pubDate>Thu, 06 Oct 2022 15:39:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1664390393370/jp73kRYsX.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-are-hooks">What are hooks?</h3>
<p>Hooks are basically meant to maintain state in ReactJS without writing a class component. 
Hooks are a new addition in React 16.8. There are various hooks in react for different purposes. Let us see what is a useState hook.  </p>
<h3 id="heading-the-usestate-hook">The useState hook</h3>
<p>The <strong>useState()</strong> is a Hook that allows you to have state variables in functional components. so basically useState is the ability to encapsulate local state in a functional component. When thinking about functionality, useState allows thinking in <strong>two or more states</strong>. Then events are required to change the state from one value to another.  </p>
<h3 id="heading-the-usestate-cycle">The useState cycle</h3>
<p> <strong>state → event → state</strong>   </p>
<h3 id="heading-syntax">Syntax</h3>
<pre><code class="lang-javascript"> <span class="hljs-keyword">const</span> [state, setState] = useState(initialState);
</code></pre>
<p>Here<br /><code>state</code> - Name of the state<br /><code>setState</code> - The function eventually used to change the value of this state<br /><code>initialState</code> - The initial value of the state<br />The only argument we pass in useState is the initial state. useState returns two values, the current state and the function that updates the state.<br /><code>useState()</code> can only be used in functional components and not class components.
We need to import <code>useState</code> from <code>react</code> in order to use it.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
</code></pre>
<h3 id="heading-example">Example</h3>
<p>Increase counter on <code>+</code> button click and decrease counter on <code>-</code> button click and display the counter.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);
</code></pre>
<p>Now we will define the <code>setCount()</code> function.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> increaseCount = <span class="hljs-function">() =&gt;</span> setCount(<span class="hljs-function"><span class="hljs-params">count</span> =&gt;</span> count + <span class="hljs-number">1</span>);
<span class="hljs-keyword">const</span> decreaseCount = <span class="hljs-function">() =&gt;</span> setCount(<span class="hljs-function"><span class="hljs-params">count</span> =&gt;</span> count - <span class="hljs-number">1</span>);
</code></pre>
<p>Here we are passing the parameter as count to <code>setCount()</code> which on every call of <code>increaseCount()</code> gets incremented by 1 and of <code>decreaseCount()</code> gets decremented by 1.</p>
<pre><code class="lang-javascript">&lt;button onClick = {decreaseCount}&gt; - &lt;/button&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span> {counter} <span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span> = <span class="hljs-string">{increaseCount}</span>&gt;</span> + <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
</code></pre>
<p>Here on clicking <code>-</code> button every time, <code>decreaseCount()</code> function gets called and the counter is decreased by 1. On clicking <code>+</code> button every tine, <code>increaseCount()</code> function gets called and the counter is increased by 1. To display the counter, simply put the <code>{counter}</code> variable in <code>HTML tag</code>.<br /><strong>Output initially</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1664734705523/3JLq79C1F.png" alt="Screenshot 2022-10-02 234741.png" class="image--center mx-auto" />
<strong>Output after clicking on <code>-</code> button one time and <code>+</code> button two times respectively</strong>  </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1664737014627/tBrBKdm6L.jpg" alt="collage.jpg" class="image--center mx-auto" /></p>
<p>This was all about the introduction of <code>useState()</code> hook in react. Congrats! After this article you are well known about how to use <code>useState()</code>, why to use <code>useState()</code> and many more basic concepts related to it!  </p>
<p><iframe src="https://giphy.com/embed/XzXjgGZOiTjF7d0JOp" width="480" height="270" class="giphy-embed"></iframe></p><p><a href="https://giphy.com/gifs/Sigruncom-wooo-hurray-wahooo-XzXjgGZOiTjF7d0JOp"></a></p><p></p>
]]></content:encoded></item><item><title><![CDATA[CSS Selectors]]></title><description><![CDATA[We know how to write HTML, but how to set some properties to that HTML element? 🤔To set the properties to HTML elements, we have CSS selectors!!
What are CSS selectors?
CSS selectors define the elements to which a set of CSS rules apply.
Basic selec...]]></description><link>https://harshalini-pandhare.hashnode.dev/css-selectors</link><guid isPermaLink="true">https://harshalini-pandhare.hashnode.dev/css-selectors</guid><category><![CDATA[CSS]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[styling]]></category><dc:creator><![CDATA[Harshalini Pandhare]]></dc:creator><pubDate>Sat, 14 May 2022 04:46:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1652503443931/ibyTiogpo.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We know how to write HTML, but how to set some properties to that HTML element? 🤔<br />To set the properties to HTML elements, we have CSS selectors!!</p>
<h2 id="heading-what-are-css-selectors">What are CSS selectors?</h2>
<p>CSS selectors define the elements to which a set of CSS rules apply.</p>
<h3 id="heading-basic-selectors">Basic selectors</h3>
<h4 id="heading-1-universal-selector">1. Universal selector</h4>
<p>A universal selector selects all elements which are present in HTML dom.<br />Syntax: <code>* { CSS body }</code></p>
<h4 id="heading-2-type-selector">2. Type selector</h4>
<p>A type selector will select a specific tag.<br />Syntax: <code>tagname { CSS body }</code><br />For example: <strong>p</strong> will select all the <code>&lt;p&gt;</code> tags in HTML DOM.</p>
<h4 id="heading-3-class-selector">3. Class selector</h4>
<p>A class selector selects all the elements with the same class attribute.<br />Syntax: <code>.classname { CSS body }</code><br />Example:  </p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">classname</span> = <span class="hljs-string">"container"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">classname</span> = <span class="hljs-string">"container"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-CSS"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">margin</span>: auto;
}
</code></pre>
<h4 id="heading-4-id-selector">4. ID selector</h4>
<p>An ID selector selects an elements based on its ID attribute.<br />Syntax: <code>#id { CSS body }</code><br />Example: </p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span> = <span class="hljs-string">"container"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-CSS"><span class="hljs-selector-id">#container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">margin</span>: auto;
}
</code></pre>
<h4 id="heading-5-attribute-selector">5. Attribute selector</h4>
<p>An attribute selector selects all the elements with the same attribute.<br />Syntax: <code>[attr] [attr=value] [attr~=value] [attr|=value] [attr^=value] [attr$=value] [attr*=value]</code><br />Example:</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span> = <span class="hljs-string">"radio"</span> /&gt;</span>
    This is input
<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
</code></pre>
<pre><code class="lang-CSS"><span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type = <span class="hljs-string">"radio"</span>]</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.5rem</span>;
}
</code></pre>
<h3 id="heading-grouping-selectors">Grouping Selectors</h3>
<p><code>,</code> is used to group various elements for which we have to set the same properties.<br />Syntax: <code>a, b { CSS body }</code><br />Example: <code>div, section</code></p>
<h3 id="heading-combinators">Combinators</h3>
<h4 id="heading-1-descendant-combinator">1. Descendant combinator</h4>
<p><code>" "</code> selects nodes that are descendants of the first element.<br />Syntax: <code>a b { CSS body }</code><br />Example: <code>div p</code> will match all <code>&lt;p&gt;</code> elements that are inside a <code>&lt;div&gt;</code> element.  </p>
<h4 id="heading-2-child-combinator">2. Child combinator</h4>
<p><code>&gt;</code> combinator selects the elements that are direct children of the first element.<br />Syntax: <code>a &gt; b { CSS body }</code><br />Example: <code>div &gt; span</code> will match all <code>&lt;span&gt;</code> which are direct children of <code>&lt;div&gt;</code> element.  </p>
<h4 id="heading-3-general-sibling-combinator">3. General sibling combinator</h4>
<p><code>~</code> combinator selects siblings. This means that the elements are consecutively and both share the same parent. 
Syntax: <code>a ~ b</code> 
Example: <code>p ~ span</code> will match all <code>&lt;span&gt;</code> elements that follow a <code>&lt;p&gt;</code>, immediately or not.</p>
<h4 id="heading-4-adjacent-sibling-combinator">4. Adjacent sibling combinator</h4>
<p>The <code>+</code> combinator only matches the second element if it immediately follows the first element. 
Syntax: <code>a + b { CSS body }</code><br />Example: <code>h1 + span</code> will match all <code>&lt;span&gt;</code> elements that immediately follow an <code>&lt;h1&gt;</code> element.</p>
<h4 id="heading-5-column-combinator-experimental">5. Column combinator Experimental</h4>
<p><code>||</code> combinator selects nodes which belong to a column.<br />Syntax: <code>a || b { CSS body }</code><br />Example: <code>col || td</code> will match all <code>&lt;td&gt;</code> elements that belong to the <code>&lt;col&gt;</code> scope.  </p>
<p><strong>So that's it! These are all the CSS selectors covered.</strong><br />We learned how to select an element with the help of CSS selectors. We learned the basic selectors, grouping selectors, and combinators. Now you can easily select any element and pace your CSS journey!🤩</p>
]]></content:encoded></item><item><title><![CDATA[Nullish Coalescing Operator (??) in JavaScript]]></title><description><![CDATA[What is a Nullish Coalescing Operator?
The nullish coalescing operator returns the right-hand side expression if the left-hand side expression is null or undefined.This operator is written as two question marks ??  
Operator precedence:

  
    Prece...]]></description><link>https://harshalini-pandhare.hashnode.dev/nullish-coalescing-operator-in-javascript</link><guid isPermaLink="true">https://harshalini-pandhare.hashnode.dev/nullish-coalescing-operator-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[ES6]]></category><category><![CDATA[coding]]></category><dc:creator><![CDATA[Harshalini Pandhare]]></dc:creator><pubDate>Tue, 10 May 2022 17:41:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1652204000281/cIza1Y2Rz.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-is-a-nullish-coalescing-operator">What is a Nullish Coalescing Operator?</h3>
<p>The nullish coalescing operator returns the right-hand side expression if the left-hand side expression is null or undefined.<br />This operator is written as two question marks <code>??</code>  </p>
<p>Operator precedence:</p>
<table>
  <tr>
    <th>Precendence</th>
    <th>Operator</th>
<th>Associativity</th>
<th>Syntax</th>

  </tr>
  <tr>
 <td>4</td>
<td>Logical OR <code>(||)</code></td>
<td>left-to-right</td>
<td><code>..||..</code></td>
  </tr> 
  <tr>
<td>4</td>
    <td>Nullish coalescing operator <code>(??)</code></td>
    <td>left-to-right</td>
   <td><code>..??..</code></td>
  </tr>
<tr>
<td>3</td>
    <td>Conditional (Ternary)</td>
    <td>left-to-right</td>
   <td><code>..?.. : ..</code></td>
  </tr>
</table>

<p>Syntax: <code>left-hand-side-expression ?? right-hand-side-expression</code>  </p>
<p>Let's take a deep dive to understand how the nullish coalescing operator works!  </p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> foo;
<span class="hljs-built_in">console</span>.log(foo ?? <span class="hljs-string">"hi!"</span>)
<span class="hljs-comment">// Output : hi!</span>
</code></pre>
<p>Here we are not initializing variable foo with any value i.e. it is undefined. That's why the right-hand-side expression is getting printed.</p>
<p>Let us see the same example using the ternary operator.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> foo;
<span class="hljs-built_in">console</span>.log((foo !== <span class="hljs-literal">undefined</span> || foo !== <span class="hljs-literal">null</span>) ? foo : <span class="hljs-string">"hi!"</span>)
<span class="hljs-comment">// Output : hi!</span>
</code></pre>
<p>As we can see, both the outputs we get, one by using the nullish coalescing operator and the other by using the ternary operator are the same.</p>
<h4 id="heading-what-is-the-difference-between-nullish-coalescing-operator-and-ternary-operator">What is the difference between nullish coalescing operator and ternary operator?</h4>
<p><em>The main difference is that the ternary operator returns the right-hand side expression if the left-hand side expression has a <strong>falsy value</strong> while the nullish coalescing operator returns the right-hand side expression if the left-hand side expression is <strong>null or undefined (but no other falsy values)</strong> </em></p>
<p></p><table>
  <tr>
    <th>Right-hand side expression is returned in</th>
    <th>  If left-hand side expression</th><p></p>
<p>  </p></tr>
  <tr>
    <td>Nullish Coalescing</td>
    <td>is null or undefined (but no other falsy values)</td><p></p>
<p>  </p></tr>
  <tr>
    <td>Ternary</td>
    <td>has a falsy value</td><p></p>
<p>  </p></tr>
</table><p></p>
<h3 id="heading-what-are-the-falsy-values">What are the falsy values?</h3>
<p>Falsy evaluates to false.<br />There are total 6 falsy values in JavaScript</p>
<ul>
<li>undefined</li>
<li>null</li>
<li>NaN</li>
<li>0</li>
<li>""   <code>//empty string</code></li>
<li>false</li>
</ul>
<p>Let us see the examples:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> obj = {
    <span class="hljs-attr">isBoy</span> : <span class="hljs-literal">false</span>,
    <span class="hljs-attr">rollNo</span> : <span class="hljs-number">45</span>
}
<span class="hljs-keyword">const</span> nullishVal = obj.isBoy ?? obj.rollNo
<span class="hljs-built_in">console</span>.log(nullishVal) <span class="hljs-comment">// Output : false</span>

<span class="hljs-keyword">const</span> ternaryVal = obj.isBoy ? obj.isBoy : obj.rollNo
<span class="hljs-built_in">console</span>.log(ternaryVal) <span class="hljs-comment">// Output : 45</span>

<span class="hljs-keyword">const</span> logicalOrVal = obj.isBoy || obj.rollNo
<span class="hljs-built_in">console</span>.log(logicalOrVal) <span class="hljs-comment">// Output : 45</span>
</code></pre>
<p>Here <code>obj.isBoy</code> is neither <code>undefined</code> nor <code>null</code>, it is <code>false</code>, that's why the <code>nullishVal</code> is returning the value of <code>obj.isBoy</code>
while <code>ternaryVal</code> and <code>logicalOrVal</code> are returning the <code>obj.rollNo</code> i.e. 45 as the value of <code>obj.isBoy</code> is <strong>falsy</strong>.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> price = <span class="hljs-number">0</span>;
<span class="hljs-built_in">console</span>.log(price || <span class="hljs-number">100</span>) <span class="hljs-comment">// Output : 100</span>
<span class="hljs-built_in">console</span>.log(price ? price : <span class="hljs-number">100</span>) <span class="hljs-comment">//Output: 100</span>
<span class="hljs-built_in">console</span>.log(price ?? <span class="hljs-number">100</span>) <span class="hljs-comment">// Output : 0</span>
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> name = <span class="hljs-literal">null</span>;
<span class="hljs-keyword">const</span> age = <span class="hljs-number">20</span>;
<span class="hljs-keyword">const</span> height = <span class="hljs-literal">undefined</span>;
<span class="hljs-built_in">console</span>.log(name ?? age ?? height ?? <span class="hljs-string">"Nothing"</span>) <span class="hljs-comment">// Output : 20</span>
<span class="hljs-comment">//Returns first value which is neither null nor undefined</span>
<span class="hljs-built_in">console</span>.log(name || age || height || <span class="hljs-string">"Nothing"</span>) <span class="hljs-comment">// Output : 20</span>
<span class="hljs-comment">//Returns first defined value</span>
</code></pre>
<p>Example using function:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> A = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"a"</span>);
  <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
}
<span class="hljs-keyword">const</span> B = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"b"</span>);
  <span class="hljs-keyword">return</span> <span class="hljs-string">"function B"</span>;
}
<span class="hljs-keyword">const</span> C = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"c"</span>);
  <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>;
}
A() ?? B() <span class="hljs-comment">// Output : a b</span>
<span class="hljs-comment">// As A() is returning null value both functions will be evaluated</span>
C() ?? B() <span class="hljs-comment">// Output: c</span>
<span class="hljs-comment">// "" is a falsy value but not null or undefined so C() will be evaluated</span>
</code></pre>
<p>Now that you have understood the basics of nullish coalescing operator and what is difference between <code>..??..</code>, <code>..?.. : ..</code>, <code>..||..</code> <strong>YOU ARE READY TO ROCK THE OPERATOR!!!</strong>.🤩</p>
<iframe src="https://giphy.com/embed/EOpZ7XsVfTN2E" width="480" height="242" class="giphy-embed"></iframe>]]></content:encoded></item></channel></rss>