<?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[Master JavaScript in 7 Days]]></title><description><![CDATA[Make beginners comfortable with JavaScript fundamentals through examples, visuals, and coding tasks one topic per day.]]></description><link>https://tirandazadiba.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 23 Jun 2026 14:47:38 GMT</lastBuildDate><atom:link href="https://tirandazadiba.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Day 7 : LocalStorage & JSON in JavaScript]]></title><description><![CDATA[Modern web apps often need to store data in the browser—such as user preferences, cart items, form data, login tokens, or theme selections.JavaScript provides LocalStorage for this and JSON to store data in a structured format.
Understanding these tw...]]></description><link>https://tirandazadiba.hashnode.dev/day-7-localstorage-and-json-in-javascript</link><guid isPermaLink="true">https://tirandazadiba.hashnode.dev/day-7-localstorage-and-json-in-javascript</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Adiba Tirandaz]]></dc:creator><pubDate>Tue, 18 Nov 2025 12:01:53 GMT</pubDate><content:encoded><![CDATA[<p>Modern web apps often need to store data in the browser—such as user preferences, cart items, form data, login tokens, or theme selections.<br />JavaScript provides <strong>LocalStorage</strong> for this and <strong>JSON</strong> to store data in a structured format.</p>
<p>Understanding these two will help you build user-friendly, persistent features without needing a backend.</p>
<hr />
<h1 id="heading-what-is-localstorage"><strong>What Is LocalStorage?</strong></h1>
<p>LocalStorage is a built-in browser storage system that allows you to save data <strong>directly on the user’s device</strong>.</p>
<p>Key points:</p>
<ul>
<li><p>Stores data as <strong>key–value pairs</strong></p>
</li>
<li><p>Data <strong>never expires</strong> unless manually cleared</p>
</li>
<li><p>Only supports <strong>strings</strong></p>
</li>
<li><p>Can store up to ~5MB in most browsers</p>
</li>
</ul>
<p>This makes it ideal for:</p>
<ul>
<li><p>Saving cart items</p>
</li>
<li><p>Storing user theme preference</p>
</li>
<li><p>Saving form inputs</p>
</li>
<li><p>Saving login tokens (not recommended for sensitive data)</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-js"><span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"name"</span>, <span class="hljs-string">"Adiba"</span>);
</code></pre>
<hr />
<h1 id="heading-basic-localstorage-methods"><strong>Basic LocalStorage Methods</strong></h1>
<pre><code class="lang-js"><span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"key"</span>, <span class="hljs-string">"value"</span>);  <span class="hljs-comment">// Save</span>
<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"key"</span>);          <span class="hljs-comment">// Read</span>
<span class="hljs-built_in">localStorage</span>.removeItem(<span class="hljs-string">"key"</span>);       <span class="hljs-comment">// Remove one</span>
<span class="hljs-built_in">localStorage</span>.clear();                 <span class="hljs-comment">// Remove all</span>
</code></pre>
<p>Example:</p>
<pre><code class="lang-js"><span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"city"</span>, <span class="hljs-string">"Pune"</span>);
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"city"</span>));
</code></pre>
<hr />
<h1 id="heading-why-json-is-needed"><strong>Why JSON Is Needed</strong></h1>
<p>LocalStorage can only store <strong>strings</strong>.<br />But we often need to store objects or arrays.</p>
<p>Example object:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> user = { <span class="hljs-attr">name</span>: <span class="hljs-string">"Adiba"</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">25</span> };
</code></pre>
<p>We cannot store this directly.<br />So we use JSON to <strong>convert</strong> objects into strings and back.</p>
<hr />
<h1 id="heading-jsonstringify-and-jsonparse"><strong>JSON.stringify() and JSON.parse()</strong></h1>
<p>These two functions allow storing structured data.</p>
<h3 id="heading-convert-object-string">Convert object → string</h3>
<pre><code class="lang-js"><span class="hljs-built_in">JSON</span>.stringify(user);
</code></pre>
<h3 id="heading-convert-string-object">Convert string → object</h3>
<pre><code class="lang-js"><span class="hljs-built_in">JSON</span>.parse(storedValue);
</code></pre>
<p>Example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> user = { <span class="hljs-attr">name</span>: <span class="hljs-string">"Adiba"</span>, <span class="hljs-attr">role</span>: <span class="hljs-string">"Frontend Developer"</span> };

<span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"user"</span>, <span class="hljs-built_in">JSON</span>.stringify(user));

<span class="hljs-keyword">const</span> data = <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"user"</span>));
<span class="hljs-built_in">console</span>.log(data.role);
</code></pre>
<hr />
<h1 id="heading-why-json-is-important"><strong>Why JSON Is Important</strong></h1>
<ul>
<li><p>Most APIs return JSON data</p>
</li>
<li><p>Makes data transferable between systems</p>
</li>
<li><p>Helps store complex data in LocalStorage</p>
</li>
<li><p>Used across JavaScript, Node.js, Angular, React, Python, etc.</p>
</li>
</ul>
<p>JSON is the universal data language of the web.</p>
<hr />
<h1 id="heading-day-7-practical-tasks-copy-paste-ready"><strong>Day 7 Practical Tasks (Copy-Paste Ready)</strong></h1>
<p>Below are tasks ready to test directly in your browser console or your HTML project.</p>
<hr />
<h2 id="heading-1-save-user-name-to-localstorage"><strong>1. Save User Name to LocalStorage</strong></h2>
<pre><code class="lang-js"><span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"username"</span>, <span class="hljs-string">"Adiba"</span>);
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"username"</span>));
</code></pre>
<hr />
<h2 id="heading-2-save-an-object-using-json"><strong>2. Save an Object Using JSON</strong></h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> profile = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Adiba"</span>,
  <span class="hljs-attr">city</span>: <span class="hljs-string">"Pune"</span>,
  <span class="hljs-attr">stack</span>: <span class="hljs-string">"Frontend"</span>
};

<span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"profile"</span>, <span class="hljs-built_in">JSON</span>.stringify(profile));

<span class="hljs-keyword">const</span> savedProfile = <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"profile"</span>));
<span class="hljs-built_in">console</span>.log(savedProfile.city);
</code></pre>
<hr />
<h2 id="heading-3-save-an-array-eg-cart-items"><strong>3. Save an Array (e.g., Cart Items)</strong></h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> cart = [<span class="hljs-string">"Shoes"</span>, <span class="hljs-string">"Bag"</span>, <span class="hljs-string">"Bottle"</span>];

<span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"cart"</span>, <span class="hljs-built_in">JSON</span>.stringify(cart));

<span class="hljs-keyword">const</span> savedCart = <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"cart"</span>));
<span class="hljs-built_in">console</span>.log(savedCart[<span class="hljs-number">1</span>]); <span class="hljs-comment">// Bag</span>
</code></pre>
<hr />
<h2 id="heading-4-remove-a-specific-item"><strong>4. Remove a Specific Item</strong></h2>
<pre><code class="lang-js"><span class="hljs-built_in">localStorage</span>.removeItem(<span class="hljs-string">"cart"</span>);
</code></pre>
<hr />
<h2 id="heading-5-clear-all-localstorage"><strong>5. Clear All LocalStorage</strong></h2>
<pre><code class="lang-js"><span class="hljs-built_in">localStorage</span>.clear();
</code></pre>
<hr />
<h2 id="heading-6-save-form-input-in-localstorage-live-saving"><strong>6. Save Form Input in LocalStorage (Live Saving)</strong></h2>
<h3 id="heading-html">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter Email"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"show"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> email = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"email"</span>);
<span class="hljs-keyword">const</span> show = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"show"</span>);

email.addEventListener(<span class="hljs-string">"input"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"emailValue"</span>, email.value);
  show.textContent = email.value;
});

<span class="hljs-comment">// Load saved data on refresh</span>
<span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"load"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> saved = <span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"emailValue"</span>);
  <span class="hljs-keyword">if</span> (saved) {
    email.value = saved;
    show.textContent = saved;
  }
});
</code></pre>
<hr />
<h2 id="heading-7-dark-mode-toggle-using-localstorage"><strong>7. Dark Mode Toggle Using LocalStorage</strong></h2>
<h3 id="heading-html-1">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"toggle"</span>&gt;</span>Toggle Theme<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-1">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> toggle = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"toggle"</span>);

toggle.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> current = <span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"theme"</span>);

  <span class="hljs-keyword">if</span> (current === <span class="hljs-string">"dark"</span>) {
    <span class="hljs-built_in">document</span>.body.style.background = <span class="hljs-string">"white"</span>;
    <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"theme"</span>, <span class="hljs-string">"light"</span>);
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-built_in">document</span>.body.style.background = <span class="hljs-string">"#222"</span>;
    <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">"theme"</span>, <span class="hljs-string">"dark"</span>);
  }
});

<span class="hljs-comment">// On page load</span>
<span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"load"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> saved = <span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">"theme"</span>);
  <span class="hljs-keyword">if</span> (saved === <span class="hljs-string">"dark"</span>) {
    <span class="hljs-built_in">document</span>.body.style.background = <span class="hljs-string">"#222"</span>;
  }
});
</code></pre>
<hr />
<h1 id="heading-closing-line"><strong>Closing Line</strong></h1>
<p>LocalStorage lets you persist data directly in the browser, and JSON helps convert complex objects into a format that can be saved and restored easily—skills that form a strong foundation for building modern web applications.</p>
<hr />
<p>Completing JavaScript is a milestone worth celebrating. You’ve covered everything from variables and functions to DOM events, LocalStorage, and JSON—each skill forming the foundation of real frontend development. With this, you’ve built the core mindset every developer needs: understanding how the browser works, how data flows, and how user interactions shape the UI. This completes your JavaScript basics journey and opens the door to mastering frameworks like Angular with confidence.</p>
]]></content:encoded></item><item><title><![CDATA[Day 6 : Events & Form Input in JavaScript]]></title><description><![CDATA[Events are the way web pages react to user actions.Whenever a user clicks, types, scrolls, submits a form, or hovers over an element — the browser triggers an event.JavaScript allows us to listen to these events and run custom code in response.
Learn...]]></description><link>https://tirandazadiba.hashnode.dev/day-6-events-and-form-input-in-javascript</link><guid isPermaLink="true">https://tirandazadiba.hashnode.dev/day-6-events-and-form-input-in-javascript</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Adiba Tirandaz]]></dc:creator><pubDate>Tue, 18 Nov 2025 11:58:44 GMT</pubDate><content:encoded><![CDATA[<hr />
<p>Events are the way web pages react to user actions.<br />Whenever a user clicks, types, scrolls, submits a form, or hovers over an element — the browser triggers an event.<br />JavaScript allows us to listen to these events and run custom code in response.</p>
<p>Learning events is important because every interactive feature in modern frontend development is built on this foundation.</p>
<hr />
<h1 id="heading-what-are-events"><strong>What Are Events?</strong></h1>
<p>An <strong>event</strong> is any action performed by the user or browser.<br />Some common examples:</p>
<ul>
<li><p>Clicking a button</p>
</li>
<li><p>Typing inside an input</p>
</li>
<li><p>Submitting a form</p>
</li>
<li><p>Hovering the mouse over an element</p>
</li>
<li><p>Pressing a keyboard key</p>
</li>
<li><p>Resizing or scrolling the page</p>
</li>
</ul>
<p>Events allow JavaScript to become interactive instead of being static.</p>
<p>Example:<br />A button doesn’t <em>do</em> anything by default — but with events, you can make it show a message, change text, add a new element, or update the UI.</p>
<hr />
<h1 id="heading-event-listeners"><strong>Event Listeners</strong></h1>
<p>An event listener is a function that waits for an event and then runs code when the event happens.</p>
<p>Syntax:</p>
<pre><code class="lang-js">element.addEventListener(<span class="hljs-string">"eventName"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>);</span>
</code></pre>
<p>Example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> btn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"btn"</span>);

btn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Button was clicked"</span>);
});
</code></pre>
<p>The browser listens for a click on the button.<br />When the click happens, the callback function runs.</p>
<hr />
<h1 id="heading-why-events-are-important"><strong>Why Events Are Important</strong></h1>
<p>Events are used in almost every feature:</p>
<ul>
<li><p>Showing validation messages</p>
</li>
<li><p>Updating the UI in real-time</p>
</li>
<li><p>Controlling forms</p>
</li>
<li><p>Opening/closing menus</p>
</li>
<li><p>Handling cart actions in e-commerce</p>
</li>
<li><p>Playing/pausing media</p>
</li>
<li><p>Managing dark mode toggles</p>
</li>
</ul>
<p>Every dynamic website relies heavily on event handling.</p>
<hr />
<h1 id="heading-working-with-form-inputs"><strong>Working With Form Inputs</strong></h1>
<p>Form inputs let users enter data.<br />JavaScript can read, validate, and update UI based on user input.</p>
<p>Example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> email = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"email"</span>).value;
</code></pre>
<p>The value updates automatically as the user types.<br />By listening to events, you can respond instantly.</p>
<hr />
<h1 id="heading-important-form-events"><strong>Important Form Events</strong></h1>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Event</td><td>When it fires</td></tr>
</thead>
<tbody>
<tr>
<td><code>input</code></td><td>On every keystroke</td></tr>
<tr>
<td><code>change</code></td><td>When input loses focus after change</td></tr>
<tr>
<td><code>focus</code></td><td>When input is clicked inside</td></tr>
<tr>
<td><code>blur</code></td><td>When input loses focus</td></tr>
<tr>
<td><code>submit</code></td><td>When form is submitted</td></tr>
</tbody>
</table>
</div><p>These events help build real-time validation, previews, button enabling/disabling, and more.</p>
<hr />
<h1 id="heading-preventing-form-reload"><strong>Preventing Form Reload</strong></h1>
<p>Forms reload pages by default.<br />To stop this, use:</p>
<pre><code class="lang-js">e.preventDefault();
</code></pre>
<p>This is essential for custom form handling.</p>
<hr />
<h1 id="heading-day-6-practical-tasks-with-html-js"><strong>Day 6 Practical Tasks (With HTML + JS)</strong></h1>
<p>All examples are ready to copy-paste and test.</p>
<hr />
<h2 id="heading-1-button-click-change-text"><strong>1. Button Click → Change Text</strong></h2>
<h3 id="heading-html">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"heading"</span>&gt;</span>Hello User<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"changeBtn"</span>&gt;</span>Click Me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> heading = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"heading"</span>);
<span class="hljs-keyword">const</span> changeBtn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"changeBtn"</span>);

changeBtn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  heading.textContent = <span class="hljs-string">"Text Updated"</span>;
});
</code></pre>
<hr />
<h2 id="heading-2-live-input-preview"><strong>2. Live Input Preview</strong></h2>
<h3 id="heading-html-1">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nameInput"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Type your name..."</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"preview"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-1">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> nameInput = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"nameInput"</span>);
<span class="hljs-keyword">const</span> preview = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"preview"</span>);

nameInput.addEventListener(<span class="hljs-string">"input"</span>, <span class="hljs-function">() =&gt;</span> {
  preview.textContent = nameInput.value;
});
</code></pre>
<hr />
<h2 id="heading-3-form-submission-handling"><strong>3. Form Submission Handling</strong></h2>
<h3 id="heading-html-2">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"myForm"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Email"</span> /&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-2">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> form = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"myForm"</span>);
<span class="hljs-keyword">const</span> email = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"email"</span>);

form.addEventListener(<span class="hljs-string">"submit"</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
  e.preventDefault();
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Email submitted:"</span>, email.value);
});
</code></pre>
<hr />
<h2 id="heading-4-highlight-input-on-focus"><strong>4. Highlight Input on Focus</strong></h2>
<h3 id="heading-html-3">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"focusInput"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Click inside me"</span> /&gt;</span>
</code></pre>
<h3 id="heading-javascript-3">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> focusInput = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"focusInput"</span>);

focusInput.addEventListener(<span class="hljs-string">"focus"</span>, <span class="hljs-function">() =&gt;</span> {
  focusInput.style.border = <span class="hljs-string">"2px solid purple"</span>;
});

focusInput.addEventListener(<span class="hljs-string">"blur"</span>, <span class="hljs-function">() =&gt;</span> {
  focusInput.style.border = <span class="hljs-string">"1px solid gray"</span>;
});
</code></pre>
<hr />
<h2 id="heading-5-detect-key-presses"><strong>5. Detect Key Presses</strong></h2>
<h3 id="heading-html-4">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"keyCheck"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Press any key..."</span> /&gt;</span>
</code></pre>
<h3 id="heading-javascript-4">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> keyCheck = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"keyCheck"</span>);

keyCheck.addEventListener(<span class="hljs-string">"keydown"</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Key pressed:"</span>, e.key);
});
</code></pre>
<hr />
<h2 id="heading-6-enable-button-only-when-input-has-text"><strong>6. Enable Button Only When Input Has Text</strong></h2>
<h3 id="heading-html-5">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"userInput"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Type something..."</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"submitBtn"</span> <span class="hljs-attr">disabled</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-5">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> userInput = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"userInput"</span>);
<span class="hljs-keyword">const</span> submitBtn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"submitBtn"</span>);

userInput.addEventListener(<span class="hljs-string">"input"</span>, <span class="hljs-function">() =&gt;</span> {
  submitBtn.disabled = userInput.value.length === <span class="hljs-number">0</span>;
});
</code></pre>
<hr />
<h1 id="heading-closing-line"><strong>Closing Line</strong></h1>
<p>Events turn static webpages into interactive applications, and understanding how to handle user input lays the foundation for building modern, dynamic UI experiences in frameworks like Angular.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Day 5 : DOM Manipulation in JavaScript]]></title><description><![CDATA[OM stands for Document Object Model.The browser converts HTML into a tree-like structure, and JavaScript can read, update, create, or delete elements from this tree.
Understanding DOM manipulation is important for every frontend developer before movi...]]></description><link>https://tirandazadiba.hashnode.dev/day-5-dom-manipulation-in-javascript</link><guid isPermaLink="true">https://tirandazadiba.hashnode.dev/day-5-dom-manipulation-in-javascript</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Adiba Tirandaz]]></dc:creator><pubDate>Tue, 18 Nov 2025 11:50:17 GMT</pubDate><content:encoded><![CDATA[<p>OM stands for <strong>Document Object Model</strong>.<br />The browser converts HTML into a tree-like structure, and JavaScript can read, update, create, or delete elements from this tree.</p>
<p>Understanding DOM manipulation is important for every frontend developer before moving to frameworks like Angular.</p>
<hr />
<h2 id="heading-what-is-the-dom"><strong>What is the DOM?</strong></h2>
<ul>
<li><p>The DOM represents the webpage as a tree of nodes.</p>
</li>
<li><p>Each HTML element becomes a JavaScript object.</p>
</li>
<li><p>JavaScript can select and modify these objects.</p>
</li>
</ul>
<p>Example representation:</p>
<pre><code class="lang-javascript">Document
 ┗━ &lt;body&gt;
      ┗━ &lt;div&gt;
            ┗━ &lt;p&gt;
</code></pre>
<hr />
<h1 id="heading-selecting-elements"><strong>Selecting Elements</strong></h1>
<pre><code class="lang-js"><span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"title"</span>);
<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".btn"</span>);
<span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">"p"</span>);
</code></pre>
<p><strong>Console Example</strong></p>
<pre><code class="lang-js"><span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"title"</span>));
</code></pre>
<hr />
<h1 id="heading-changing-text-content"><strong>Changing Text Content</strong></h1>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> title = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"title"</span>);
title.textContent = <span class="hljs-string">"Updated Title"</span>;
</code></pre>
<p><strong>Console Example</strong></p>
<pre><code class="lang-js"><span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"title"</span>).textContent = <span class="hljs-string">"Hello from Console"</span>;
</code></pre>
<hr />
<h1 id="heading-changing-styles"><strong>Changing Styles</strong></h1>
<pre><code class="lang-js">title.style.color = <span class="hljs-string">"purple"</span>;
title.style.fontSize = <span class="hljs-string">"24px"</span>;
</code></pre>
<p><strong>Console Example</strong></p>
<pre><code class="lang-js"><span class="hljs-built_in">document</span>.body.style.background = <span class="hljs-string">"lightyellow"</span>;
</code></pre>
<hr />
<h1 id="heading-changing-attributes"><strong>Changing Attributes</strong></h1>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> img = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"img"</span>);
img.src = <span class="hljs-string">"new-image.jpg"</span>;
img.alt = <span class="hljs-string">"Updated Image"</span>;
</code></pre>
<p><strong>Console Example</strong></p>
<pre><code class="lang-js"><span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"img"</span>).src = <span class="hljs-string">"https://picsum.photos/200"</span>;
</code></pre>
<hr />
<h1 id="heading-creating-elements"><strong>Creating Elements</strong></h1>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> li = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"li"</span>);
li.textContent = <span class="hljs-string">"New Item Added"</span>;
<span class="hljs-built_in">document</span>.body.appendChild(li);
</code></pre>
<p><strong>Console Example</strong></p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> p = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"p"</span>);
p.textContent = <span class="hljs-string">"This paragraph was created from the console."</span>;
<span class="hljs-built_in">document</span>.body.appendChild(p);
</code></pre>
<hr />
<h1 id="heading-removing-elements"><strong>Removing Elements</strong></h1>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> box = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"box"</span>);
box.remove();
</code></pre>
<p><strong>Console Example</strong></p>
<pre><code class="lang-js"><span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"p"</span>).remove();
</code></pre>
<hr />
<h1 id="heading-event-listeners"><strong>Event Listeners</strong></h1>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> btn = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"#btn"</span>);

btn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Button clicked"</span>);
});
</code></pre>
<hr />
<h1 id="heading-practical-tasks"><strong>Practical Tasks</strong></h1>
<p>Below are tasks you can directly try in your HTML file + console.</p>
<hr />
<h2 id="heading-1-change-page-title-on-button-click"><strong>1. Change Page Title on Button Click</strong></h2>
<h3 id="heading-html">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"title"</span>&gt;</span>Welcome<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"btn"</span>&gt;</span>Change Title<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> title = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"title"</span>);
<span class="hljs-keyword">const</span> btn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"btn"</span>);

btn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  title.textContent = <span class="hljs-string">"Hello Adiba"</span>;
});
</code></pre>
<hr />
<h2 id="heading-2-highlight-product-price"><strong>2. Highlight Product Price</strong></h2>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> price = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".price"</span>);
price.style.color = <span class="hljs-string">"green"</span>;
price.style.fontSize = <span class="hljs-string">"20px"</span>;
</code></pre>
<hr />
<h2 id="heading-3-update-product-image-on-hover"><strong>3. Update Product Image on Hover</strong></h2>
<h3 id="heading-html-1">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"productImg"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"image1.jpg"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"200"</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-1">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> img = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"productImg"</span>);

img.addEventListener(<span class="hljs-string">"mouseover"</span>, <span class="hljs-function">() =&gt;</span> {
  img.src = <span class="hljs-string">"image2.jpg"</span>;
});

img.addEventListener(<span class="hljs-string">"mouseout"</span>, <span class="hljs-function">() =&gt;</span> {
  img.src = <span class="hljs-string">"image1.jpg"</span>;
});
</code></pre>
<hr />
<h2 id="heading-4-add-new-item-to-a-list"><strong>4. Add New Item to a List</strong></h2>
<h3 id="heading-html-2">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"list"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"addBtn"</span>&gt;</span>Add Item<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-2">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> list = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"list"</span>);
<span class="hljs-keyword">const</span> addBtn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"addBtn"</span>);

addBtn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> li = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"li"</span>);
  li.textContent = <span class="hljs-string">"New Product Added"</span>;
  list.appendChild(li);
});
</code></pre>
<hr />
<h2 id="heading-5-remove-a-card-on-button-click"><strong>5. Remove a Card on Button Click</strong></h2>
<h3 id="heading-html-3">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Card Content<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"delete"</span>&gt;</span>Delete<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-3">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> del = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".delete"</span>);

del.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  del.parentElement.remove();
});
</code></pre>
<h2 id="heading-6-live-preview-while-typing"><strong>6. Live Preview While Typing</strong></h2>
<h3 id="heading-html-4">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nameInput"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Type something..."</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"preview"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<h3 id="heading-javascript-4">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> input = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"nameInput"</span>);
<span class="hljs-keyword">const</span> preview = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"preview"</span>);

input.addEventListener(<span class="hljs-string">"input"</span>, <span class="hljs-function">() =&gt;</span> {
  preview.textContent = input.value;
});
</code></pre>
<hr />
<p>Understanding DOM manipulation gives you direct control over how webpages behave, and this skill prepares you for building dynamic interfaces in frameworks like Angular.</p>
]]></content:encoded></item><item><title><![CDATA[DAY 4 : Objects & Nested Objects]]></title><description><![CDATA[Objects are the backbone of JavaScript and TypeScript.Every real-world app Angular apps, APIs, e-commerce systems, dashboards — use objects everywhere.
Think of an object like a box that stores information with labels.
⭐ What Is an Object?

An object...]]></description><link>https://tirandazadiba.hashnode.dev/day-4-objects-and-nested-objects</link><guid isPermaLink="true">https://tirandazadiba.hashnode.dev/day-4-objects-and-nested-objects</guid><category><![CDATA[DAY 4 :Objects & Nested Objects]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Adiba Tirandaz]]></dc:creator><pubDate>Tue, 18 Nov 2025 11:43:42 GMT</pubDate><content:encoded><![CDATA[<p>Objects are the backbone of JavaScript and TypeScript.<br />Every real-world app Angular apps, APIs, e-commerce systems, dashboards — use objects everywhere.</p>
<p>Think of an object like a <strong>box</strong> that stores information with <strong>labels</strong>.</p>
<h2 id="heading-what-is-an-object">⭐ <strong>What Is an Object?</strong></h2>
<ul>
<li><p>An object stores data in <strong>key–value</strong> pairs.</p>
</li>
<li><p>Keys are always <strong>strings</strong>.</p>
</li>
<li><p>Values can be <strong>anything</strong>: string, number, array, another object.</p>
</li>
</ul>
<p>Example</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> user = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Adiba"</span>,
  <span class="hljs-attr">age</span>: <span class="hljs-number">25</span>,
  <span class="hljs-attr">role</span>: <span class="hljs-string">"Frontend Developer"</span>
};
</code></pre>
<h2 id="heading-what-are-nested-objects">⭐ <strong>What Are Nested Objects?</strong></h2>
<p>A nested object is simply an object <strong>inside another object</strong>.</p>
<p>Real-world example:<br />A user has an address → and an address has city, pin, state.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> userProfile = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Adiba"</span>,
  <span class="hljs-attr">contact</span>: {
    <span class="hljs-attr">email</span>: <span class="hljs-string">"adiba@email.com"</span>,
    <span class="hljs-attr">address</span>: {
      <span class="hljs-attr">city</span>: <span class="hljs-string">"Pune"</span>,
      <span class="hljs-attr">pin</span>: <span class="hljs-number">411001</span>
    }
  }
};
</code></pre>
<p>This is exactly how <strong>user APIs</strong>, <strong>product APIs</strong>, <strong>LMS dashboards</strong>, <strong>cart systems</strong>, etc. structure data.</p>
<h2 id="heading-why-developers-use-objects-everywhere">⭐ Why Developers Use Objects Everywhere</h2>
<ul>
<li><p>Easy to group related data.</p>
</li>
<li><p>Easy to pass around as a single unit.</p>
</li>
<li><p>Flexible: you can add, update, or delete properties anytime.</p>
</li>
<li><p>Perfect representation of real-world entities.</p>
</li>
</ul>
<hr />
<h2 id="heading-accessing-object-values">⭐ Accessing Object Values</h2>
<h3 id="heading-dot-notation">Dot notation:</h3>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(userProfile.name);
<span class="hljs-built_in">console</span>.log(userProfile.contact.email);
<span class="hljs-built_in">console</span>.log(userProfile.contact.address.city);
</code></pre>
<h3 id="heading-bracket-notation">Bracket notation:</h3>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(userProfile[<span class="hljs-string">"name"</span>]);
</code></pre>
<p>Bracket notation is useful when:</p>
<ul>
<li><p>key is dynamic</p>
</li>
<li><p>key comes from a variable</p>
</li>
</ul>
<h2 id="heading-practical-e-commerce-examples"><strong>Practical E-commerce Examples</strong></h2>
<h2 id="heading-1-product-object">⭐ 1. Product Object</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> product = {
  <span class="hljs-attr">id</span>: <span class="hljs-number">101</span>,
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Wireless Mouse"</span>,
  <span class="hljs-attr">price</span>: <span class="hljs-number">899</span>,
  <span class="hljs-attr">specs</span>: {
    <span class="hljs-attr">color</span>: <span class="hljs-string">"Black"</span>,
    <span class="hljs-attr">battery</span>: <span class="hljs-string">"AA"</span>,
    <span class="hljs-attr">warranty</span>: <span class="hljs-string">"1 Year"</span>
  }
};
</code></pre>
<h2 id="heading-2-cart-array-array-of-objects">⭐ 2. Cart Array (Array of Objects)</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> cart = [
  { <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">"Shoes"</span>, <span class="hljs-attr">price</span>: <span class="hljs-number">1200</span> },
  { <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">"Bag"</span>, <span class="hljs-attr">price</span>: <span class="hljs-number">900</span> }
];
</code></pre>
<h2 id="heading-3-users-list-nested-objects-inside-array">⭐ 3. Users List (Nested Objects inside Array)</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> users = [
  {
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Aditi"</span>,
    <span class="hljs-attr">address</span>: { <span class="hljs-attr">city</span>: <span class="hljs-string">"Mumbai"</span>, <span class="hljs-attr">pin</span>: <span class="hljs-number">400001</span> }
  },
  {
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Riya"</span>,
    <span class="hljs-attr">address</span>: { <span class="hljs-attr">city</span>: <span class="hljs-string">"Pune"</span>, <span class="hljs-attr">pin</span>: <span class="hljs-number">411001</span> }
  }
];
</code></pre>
<p>Objects are the truth behind every API you consume.</p>
<h2 id="heading-4-challenges">4 Challenges</h2>
<h2 id="heading-1-product-description-generator"><strong>1. Product Description Generator</strong></h2>
<p>Input:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> product = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Laptop"</span>,
  <span class="hljs-attr">price</span>: <span class="hljs-number">55000</span>,
  <span class="hljs-attr">specs</span>: { <span class="hljs-attr">ram</span>: <span class="hljs-string">"16GB"</span>, <span class="hljs-attr">storage</span>: <span class="hljs-string">"512GB SSD"</span> }
};
</code></pre>
<p>Task:</p>
<ul>
<li>Write a function that returns:<br />  <code>"Laptop costs ₹55000 and comes with 16GB RAM and 512GB SSD"</code></li>
</ul>
<h2 id="heading-2-add-a-new-property-to-an-object"><strong>2. Add a New Property to an Object</strong></h2>
<p>Task:</p>
<ul>
<li><p>Create a function <code>addProperty(obj, key, value)</code> that:</p>
<ul>
<li><p>adds the new key/value into the object</p>
</li>
<li><p>returns updated object</p>
</li>
</ul>
</li>
</ul>
<p>This mirrors adding dynamic fields in forms or API objects.</p>
<h2 id="heading-3-nested-object-reader"><strong>3. Nested Object Reader</strong></h2>
<p>Given:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> user = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Aman"</span>,
  <span class="hljs-attr">contact</span>: {
    <span class="hljs-attr">address</span>: {
      <span class="hljs-attr">city</span>: <span class="hljs-string">"Delhi"</span>,
      <span class="hljs-attr">pin</span>: <span class="hljs-number">110001</span>
    }
  }
}
</code></pre>
<p>Task:</p>
<ul>
<li>Write a function that returns <code>"Delhi"</code> by accessing the nested city.</li>
</ul>
<p>This teaches deep property access — common in Angular templates.</p>
<h2 id="heading-4-inventory-total-price"><strong>4. Inventory Total Price</strong></h2>
<p>Given:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> items = [
  { <span class="hljs-attr">price</span>: <span class="hljs-number">100</span> },
  { <span class="hljs-attr">price</span>: <span class="hljs-number">250</span> },
  { <span class="hljs-attr">price</span>: <span class="hljs-number">150</span> }
];
</code></pre>
<p>Task:</p>
<ul>
<li>Write a function to return the <strong>total price</strong>.</li>
</ul>
<p>This mirrors calculating totals in a shopping cart.</p>
<h2 id="heading-5-compare-two-product-specifications"><strong>5. Compare Two Product Specifications</strong></h2>
<p>Given two product objects:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> p1 = { <span class="hljs-attr">name</span>: <span class="hljs-string">"Laptop A"</span>, <span class="hljs-attr">specs</span>: { <span class="hljs-attr">cpu</span>: <span class="hljs-string">"i5"</span> } };
<span class="hljs-keyword">const</span> p2 = { <span class="hljs-attr">name</span>: <span class="hljs-string">"Laptop B"</span>, <span class="hljs-attr">specs</span>: { <span class="hljs-attr">cpu</span>: <span class="hljs-string">"i7"</span> } };
</code></pre>
<p>Task:</p>
<ul>
<li>Return which one has the better CPU.</li>
</ul>
<p>This builds comparison logic — used in filtering/sorting.</p>
<p><strong>Objects form the foundation of real-world data in every frontend project, and mastering them now makes the upcoming days APIs, services, and Angular components far smoother and more intuitive.</strong></p>
]]></content:encoded></item><item><title><![CDATA[Day 3: Arrays & Loops (JavaScript Basics)]]></title><description><![CDATA[Arrays :
An array stores multiple values in a single variable.
Imagine you have a cupboard with numbered shelves.Each shelf holds one thing an apple, a banana, or even your favourite bug report.
const cupboard = ["Apple", "Banana", "Mango"];

Here:

...]]></description><link>https://tirandazadiba.hashnode.dev/day-3-arrays-and-loops-javascript-basics</link><guid isPermaLink="true">https://tirandazadiba.hashnode.dev/day-3-arrays-and-loops-javascript-basics</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[arrays]]></category><category><![CDATA[Loops]]></category><category><![CDATA[How to use Loops, Array.from, Map, Filter, and Reduce in JavaScript 🚀]]></category><category><![CDATA[#javascript, #arrays, #programming, #webdevelopment, #JavaScriptmethods, #arraymanipulation, #arrayoperations]]></category><dc:creator><![CDATA[Adiba Tirandaz]]></dc:creator><pubDate>Mon, 10 Nov 2025 11:00:30 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-arrays"><strong>Arrays :</strong></h2>
<p>An <strong>array</strong> stores multiple values in a single variable.</p>
<p>Imagine you have a cupboard with <strong>numbered shelves</strong>.<br />Each shelf holds one thing an apple, a banana, or even your favourite bug report.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> cupboard = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>];
</code></pre>
<p>Here:</p>
<ul>
<li><p>The cupboard’s <strong>name</strong> is <code>cupboard</code>.</p>
</li>
<li><p>The <strong>shelves</strong> start at <code>0</code> (JavaScript likes counting like a toddler: “zero, one, two…”).</p>
</li>
<li><p><code>cupboard[0]</code> opens the first shelf → <code>"Apple"</code>.</p>
</li>
</ul>
<p>Your array is basically a <strong>queue of items waiting for your commands</strong>.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Action</td><td>Method</td><td>Memory Trick</td></tr>
</thead>
<tbody>
<tr>
<td>Add at end</td><td><code>push()</code></td><td>Push into the cupboard</td></tr>
<tr>
<td>Remove last</td><td><code>pop()</code></td><td>Pop it out to eat</td></tr>
<tr>
<td>Add at start</td><td><code>unshift()</code></td><td>Shove to the front</td></tr>
<tr>
<td>Remove first</td><td><code>shift()</code></td><td>Slide the first out</td></tr>
<tr>
<td>Find if exists</td><td><code>includes("Mango")</code></td><td>Check if fruit is inside</td></tr>
<tr>
<td>Find position</td><td><code>indexOf("Banana")</code></td><td>“Which shelf is Banana on?”</td></tr>
</tbody>
</table>
</div><pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>];

fruits.push(<span class="hljs-string">"Orange"</span>);     <span class="hljs-comment">// Add at end</span>
fruits.pop();              <span class="hljs-comment">// Remove last</span>
fruits.unshift(<span class="hljs-string">"Pineapple"</span>); <span class="hljs-comment">// Add at start</span>
fruits.shift();            <span class="hljs-comment">// Remove first</span>

<span class="hljs-built_in">console</span>.log(fruits);       <span class="hljs-comment">// ["Apple", "Banana", "Mango"]</span>

<span class="hljs-built_in">console</span>.log(fruits.includes(<span class="hljs-string">"Mango"</span>)); <span class="hljs-comment">// true</span>
<span class="hljs-built_in">console</span>.log(fruits.indexOf(<span class="hljs-string">"Banana"</span>)); <span class="hljs-comment">// 1</span>
</code></pre>
<p>🍓 <strong>Array Slice, Splice, Concat &amp; Spread — Cutting and Mixing Fruits</strong></p>
<p>You’ve got multiple baskets in your fruit shop sometimes you take a few fruits out, sometimes you mix baskets together.<br />That’s exactly what these methods help you do.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>🍉 <strong>Action</strong></td><td>🧰 <strong>Method</strong></td><td>💬 <strong>What It Does</strong></td><td>🧠 <strong>Memory Trick</strong></td><td>⚙️ <strong>Changes Original Array?</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Take a portion (copy)</strong></td><td><code>slice(start, end)</code></td><td>Copies a section of the basket into a <strong>new basket</strong></td><td>Like <em>slicing a piece of cake</em> you take some but the rest stays</td><td>❌ No</td></tr>
<tr>
<td><strong>Remove or replace</strong></td><td><code>splice(start, count, ...newItems)</code></td><td>Removes or replaces fruits <strong>inside</strong> the basket</td><td>Like <em>doing surgery on your basket</em></td><td>✅ Yes</td></tr>
<tr>
<td><strong>Join two baskets</strong></td><td><code>concat(array2)</code></td><td>Combines two or more baskets into one</td><td>Like <em>pouring fruits into a bigger basket</em></td><td>❌ No</td></tr>
<tr>
<td><strong>Spread everything</strong></td><td><code>[...array1, ...array2]</code></td><td>Copies fruits from multiple baskets using spread syntax</td><td>Like <em>spilling both baskets into a new one</em></td><td>❌ No</td></tr>
</tbody>
</table>
</div><p>🍍 <strong>Code Example</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// 🍎 Original baskets</span>
<span class="hljs-keyword">let</span> basket1 = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>];
<span class="hljs-keyword">let</span> basket2 = [<span class="hljs-string">"Orange"</span>, <span class="hljs-string">"Kiwi"</span>];

<span class="hljs-comment">// 🍰 slice() — take a copy portion</span>
<span class="hljs-keyword">let</span> fewFruits = basket1.slice(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Sliced Portion:"</span>, fewFruits);
<span class="hljs-comment">// ["Banana", "Mango"]</span>

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"After slice:"</span>, basket1);
<span class="hljs-comment">// ["Apple", "Banana", "Mango"]</span>

<span class="hljs-comment">// 🔪 splice() — remove or replace inside</span>
basket1.splice(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-string">"Pineapple"</span>);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"After splice:"</span>, basket1);
<span class="hljs-comment">// ["Apple", "Pineapple", "Mango"]</span>

<span class="hljs-comment">// 🧺 concat() — merge baskets</span>
<span class="hljs-keyword">let</span> combined = basket1.concat(basket2);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"After concat:"</span>, combined);
<span class="hljs-comment">// ["Apple", "Pineapple", "Mango", "Orange", "Kiwi"]</span>

<span class="hljs-comment">// ✨ spread (...) — merge the modern way</span>
<span class="hljs-keyword">let</span> spreadCombined = [...basket1, ...basket2, <span class="hljs-string">"Strawberry"</span>];
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"After spread:"</span>, spreadCombined);
<span class="hljs-comment">// ["Apple", "Pineapple", "Mango", "Orange", "Kiwi", "Strawberry"]</span>
</code></pre>
<h2 id="heading-loops">Loops :</h2>
<p>A <strong>loop</strong> is a <em>repeater</em>.<br />It lets you run the same block of code multiple times automatically until a condition tells it to stop.</p>
<p>Think of a <strong>loop</strong> as your fruit shop assistant 🍊<br />who checks every shelf in your cupboard so you don’t have to repeat the same work manually.</p>
<p>🧺 <strong>Example Basket</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Orange"</span>];
</code></pre>
<p>Without a loop, you’d have to do:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(fruits[<span class="hljs-number">0</span>]);
<span class="hljs-built_in">console</span>.log(fruits[<span class="hljs-number">1</span>]);
<span class="hljs-built_in">console</span>.log(fruits[<span class="hljs-number">2</span>]);
<span class="hljs-built_in">console</span>.log(fruits[<span class="hljs-number">3</span>]);
</code></pre>
<p>Boring, right?<br />So let’s automate it!</p>
<p><strong>🧠 Types of Loops in JavaScript</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>🔢 <strong>Loop Type</strong></td><td>💻 <strong>Syntax Example</strong></td><td>💬 <strong>What It Does</strong></td><td>🪄 <strong>Memory Trick</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>for loop</strong></td><td><code>for (let i = 0; i &lt; fruits.length; i++)</code></td><td>Runs from start to end using an index counter</td><td>Classic shop assistant counting shelf by shelf</td></tr>
<tr>
<td><strong>for...of</strong></td><td><code>for (let fruit of fruits)</code></td><td>Goes through each fruit directly (no index needed)</td><td>Polite assistant who handles every fruit by name</td></tr>
<tr>
<td><strong>forEach()</strong></td><td><code>fruits.forEach(fruit =&gt; {...})</code></td><td>Executes a function once for every fruit</td><td>Modern intern following your instructions</td></tr>
<tr>
<td><strong>while</strong></td><td><code>while (condition)</code></td><td>Keeps looping <em>while</em> the condition is true</td><td>Assistant who works until you say “stop”</td></tr>
<tr>
<td><strong>do...while</strong></td><td><code>do {...} while (condition)</code></td><td>Runs at least once, then checks condition</td><td>Assistant who acts first, thinks later 😄</td></tr>
</tbody>
</table>
</div><p>🍏 <strong>1️⃣ for loop</strong></p>
<p>Your assistant counts every shelf manually.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Orange"</span>];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; fruits.length; i++) {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Fruit on shelf"</span>, i, <span class="hljs-string">"is"</span>, fruits[i]);
}

<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// Fruit on shelf 0 is Apple</span>
<span class="hljs-comment">// Fruit on shelf 1 is Banana</span>
<span class="hljs-comment">// Fruit on shelf 2 is Mango</span>
<span class="hljs-comment">// Fruit on shelf 3 is Orange</span>
</code></pre>
<p>🍌 <strong>2️⃣ for...of loop</strong></p>
<p>The polite version — ignores shelf numbers, just handles fruits directly.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Orange"</span>];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> fruit <span class="hljs-keyword">of</span> fruits) {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Selling:"</span>, fruit);
}

<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// Selling: Apple</span>
<span class="hljs-comment">// Selling: Banana</span>
<span class="hljs-comment">// Selling: Mango</span>
<span class="hljs-comment">// Selling: Orange</span>
</code></pre>
<p>🍓 <strong>3️⃣ forEach() loop</strong></p>
<p>The modern way — give one rule, and it runs for each fruit automatically.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Orange"</span>];
fruits.forEach(<span class="hljs-function"><span class="hljs-params">fruit</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Packing:"</span>, fruit));

<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// Packing: Apple</span>
<span class="hljs-comment">// Packing: Banana</span>
<span class="hljs-comment">// Packing: Mango</span>
<span class="hljs-comment">// Packing: Orange</span>
</code></pre>
<p>🍍 <strong>4️⃣ while loop</strong></p>
<p>Keeps going <em>as long as</em> a condition stays true.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Orange"</span>];
<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>;
<span class="hljs-keyword">while</span> (i &lt; fruits.length) {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Checking:"</span>, fruits[i]);
  i++;
}

<span class="hljs-comment">//Output:</span>
<span class="hljs-comment">//Checking: Apple</span>
<span class="hljs-comment">//Checking: Banana</span>
<span class="hljs-comment">//Checking: Mango</span>
<span class="hljs-comment">//Checking: Orange</span>
</code></pre>
<p>🍇 <strong>5️⃣ do...while loop</strong></p>
<p>Runs <strong>at least once</strong>, even if the condition is false.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Orange"</span>];
<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>;
<span class="hljs-keyword">do</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Fruit:"</span>, fruits[j]);
  j++;
} <span class="hljs-keyword">while</span> (j &lt; fruits.length);

<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// Fruit: Apple</span>
<span class="hljs-comment">// Fruit: Banana</span>
<span class="hljs-comment">// Fruit: Mango</span>
<span class="hljs-comment">// Fruit: Orange</span>
</code></pre>
<h3 id="heading-special-keywords-break-amp-continue">✋ <strong>Special Keywords: break &amp; continue</strong></h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Keyword</td><td>What It Does</td><td>Example Idea</td></tr>
</thead>
<tbody>
<tr>
<td><code>break</code></td><td>Stops the loop completely</td><td>Stop selling once you reach “Mango”</td></tr>
<tr>
<td><code>continue</code></td><td>Skips current item, continues next</td><td>Skip spoiled “Banana” but keep looping</td></tr>
</tbody>
</table>
</div><h4 id="heading-example">Example:</h4>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Orange"</span>];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> fruit <span class="hljs-keyword">of</span> fruits) {
  <span class="hljs-keyword">if</span> (fruit === <span class="hljs-string">"Banana"</span>) <span class="hljs-keyword">continue</span>; <span class="hljs-comment">// skip banana</span>
  <span class="hljs-keyword">if</span> (fruit === <span class="hljs-string">"Mango"</span>) <span class="hljs-keyword">break</span>;     <span class="hljs-comment">// stop at mango</span>
  <span class="hljs-built_in">console</span>.log(fruit);
}

<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// Apple</span>
</code></pre>
<h3 id="heading-when-to-use-which">🍒 <strong>When to Use Which</strong></h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Goal</td><td>Best Loop</td></tr>
</thead>
<tbody>
<tr>
<td>Fixed number of times</td><td><code>for</code></td></tr>
<tr>
<td>Go through list directly</td><td><code>for...of</code></td></tr>
<tr>
<td>Cleaner one-line operation</td><td><code>forEach()</code></td></tr>
<tr>
<td>Repeat based on condition</td><td><code>while</code></td></tr>
<tr>
<td>Run at least once</td><td><code>do...while</code></td></tr>
</tbody>
</table>
</div><h2 id="heading-smart-loops-map-filter-reduce-find">🤖 <strong>Smart Loops — map(), filter(), reduce(), find()</strong></h2>
<p>These are <strong>built-in array methods</strong> that act <em>like loops</em> but with <strong>shorter, cleaner, and smarter syntax</strong>.<br />They help you <strong>transform</strong>, <strong>filter</strong>, or <strong>summarise</strong> data all without writing manual loops.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Action</td><td>Method</td><td>What It Does</td><td>Example Result</td></tr>
</thead>
<tbody>
<tr>
<td>Transform all</td><td><code>map()</code></td><td>Create new array with changed items</td><td><code>["Apple Juice", "Banana Juice"]</code></td></tr>
<tr>
<td>Filter some</td><td><code>filter()</code></td><td>Keep only items that match</td><td><code>["Mango"]</code></td></tr>
<tr>
<td>Combine all</td><td><code>reduce()</code></td><td>Return a single total value</td><td><code>100</code></td></tr>
<tr>
<td>Find one</td><td><code>find()</code></td><td>Return first matching item</td><td><code>"Mango"</code></td></tr>
</tbody>
</table>
</div><p>🍏 <strong>1️⃣ map() — Transform Every Fruit</strong></p>
<p>Creates a <em>new array</em> by applying a function to every item.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> juices = fruits.map(<span class="hljs-function"><span class="hljs-params">fruit</span> =&gt;</span> fruit + <span class="hljs-string">" Juice"</span>);
<span class="hljs-built_in">console</span>.log(juices);
<span class="hljs-comment">// ["Apple Juice", "Banana Juice", "Mango Juice", "Orange Juice"]</span>
</code></pre>
<p>🍌 <strong>2️⃣ filter() — Keep Only the Good Ones</strong></p>
<p>Creates a <em>new array</em> with only elements that pass a test.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> selected = fruits.filter(<span class="hljs-function"><span class="hljs-params">fruit</span> =&gt;</span> fruit.startsWith(<span class="hljs-string">"M"</span>));
<span class="hljs-built_in">console</span>.log(selected);
<span class="hljs-comment">// ["Mango"]</span>
</code></pre>
<p>🍓 <strong>3️⃣ reduce() — Combine Everything into One</strong></p>
<p>Reduces the array to a single value (like sum, total, etc.)</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> numbers = [<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>, <span class="hljs-number">40</span>];
<span class="hljs-keyword">let</span> total = numbers.reduce(<span class="hljs-function">(<span class="hljs-params">sum, num</span>) =&gt;</span> sum + num, <span class="hljs-number">0</span>);
<span class="hljs-built_in">console</span>.log(total);
<span class="hljs-comment">// 100</span>
</code></pre>
<p>🍍 <strong>4️⃣ find() — Find the First Match</strong></p>
<p>Returns the <em>first element</em> that passes a condition.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> found = fruits.find(<span class="hljs-function"><span class="hljs-params">fruit</span> =&gt;</span> fruit === <span class="hljs-string">"Mango"</span>);
<span class="hljs-built_in">console</span>.log(found);
<span class="hljs-comment">// "Mango"</span>
</code></pre>
<h2 id="heading-sorting-amp-rearranging-arrays">🍇 <strong>Sorting &amp; Rearranging Arrays</strong></h2>
<p>Let’s keep our <strong>fruit basket</strong> theme going 🍎</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">"Mango"</span>, <span class="hljs-string">"Apple"</span>, <span class="hljs-string">"Banana"</span>, <span class="hljs-string">"Orange"</span>];
</code></pre>
<p>🍏 <strong>1️⃣ sort() — Arrange in Order</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Detail</td><td>Explanation</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Purpose</strong></td><td>Sorts array items alphabetically or numerically (ascending by default).</td></tr>
<tr>
<td><strong>Changes original array?</strong></td><td>✅ Yes</td></tr>
<tr>
<td><strong>Memory Trick</strong></td><td>“Arrange fruits neatly on the shelf A → Z.”</td></tr>
</tbody>
</table>
</div><pre><code class="lang-javascript">fruits.sort();
<span class="hljs-built_in">console</span>.log(fruits);
<span class="hljs-comment">// ["Apple", "Banana", "Mango", "Orange"]</span>
</code></pre>
<p>🍊 <strong>2️⃣ reverse() — Flip the Order</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Detail</td><td>Explanation</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Purpose</strong></td><td>Reverses the order of elements in the array.</td></tr>
<tr>
<td><strong>Changes original array?</strong></td><td>✅ Yes</td></tr>
<tr>
<td><strong>Memory Trick</strong></td><td>“Flip the basket upside down.” 😄</td></tr>
</tbody>
</table>
</div><pre><code class="lang-javascript">fruits.reverse();
<span class="hljs-built_in">console</span>.log(fruits);
<span class="hljs-comment">// ["Orange", "Mango", "Banana", "Apple"]</span>
</code></pre>
<p>🍓 <strong>3️⃣ join() — Turn into a String</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Detail</td><td>Explanation</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Purpose</strong></td><td>Combines all array items into one string.</td></tr>
<tr>
<td><strong>Changes original array?</strong></td><td>❌ No</td></tr>
<tr>
<td><strong>Memory Trick</strong></td><td>“Join all fruit names to print the fruit list.” 🧾</td></tr>
</tbody>
</table>
</div><pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruitString = fruits.join(<span class="hljs-string">", "</span>);
<span class="hljs-built_in">console</span>.log(fruitString);
<span class="hljs-comment">// "Orange, Mango, Banana, Apple"</span>
</code></pre>
<p>🍍 <strong>4️⃣ split() — Turn String into Array</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Detail</td><td>Explanation</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Purpose</strong></td><td>Splits a string into an array (opposite of join).</td></tr>
<tr>
<td><strong>Changes original array?</strong></td><td>❌ No</td></tr>
<tr>
<td><strong>Memory Trick</strong></td><td>“Cut a fruit list string back into individual fruits.” ✂️</td></tr>
</tbody>
</table>
</div><pre><code class="lang-javascript"><span class="hljs-keyword">let</span> newBasket = fruitString.split(<span class="hljs-string">", "</span>);
<span class="hljs-built_in">console</span>.log(newBasket);
<span class="hljs-comment">// ["Orange", "Mango", "Banana", "Apple"]</span>
</code></pre>
<p>🍇 <strong>5️⃣ sort() with Numbers (Custom Function)</strong></p>
<p><code>sort()</code> doesn’t sort numbers correctly by default (it treats them as text).<br />To sort numbers properly, use a custom function:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> prices = [<span class="hljs-number">50</span>, <span class="hljs-number">5</span>, <span class="hljs-number">20</span>, <span class="hljs-number">100</span>];
prices.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a - b);
<span class="hljs-built_in">console</span>.log(prices);
<span class="hljs-comment">// [5, 20, 50, 100]</span>
</code></pre>
<h3 id="heading-array-amp-loop-practice-questions">🧠 <strong>Array &amp; Loop Practice Questions</strong></h3>
<ol>
<li><p>Print every fruit in the array using a loop.</p>
</li>
<li><p>Print only fruits that start with the letter <strong>M</strong>.</p>
</li>
<li><p>Count how many fruits are in the basket (without using <code>.length</code>).</p>
</li>
<li><p>Reverse the array manually (don’t use <code>.reverse()</code>).</p>
</li>
<li><p>Combine two fruit baskets into one new array.</p>
</li>
<li><p>Find the fruit with the <strong>longest name</strong>.</p>
</li>
<li><p>Find the fruit with the <strong>shortest name</strong>.</p>
</li>
<li><p>Check if <code>"Kiwi"</code> exists in the basket.</p>
</li>
<li><p>Remove the first and last fruit using array methods.</p>
</li>
<li><p>Add <code>"Pineapple"</code> at the beginning and <code>"Papaya"</code> at the end.</p>
</li>
<li><p>Copy only the middle two fruits using <code>slice()</code>.</p>
</li>
<li><p>Replace <code>"Banana"</code> with <code>"Guava"</code> using <code>splice()</code>.</p>
</li>
<li><p>Create a string of all fruits separated by commas using <code>join()</code>.</p>
</li>
<li><p>Split <code>"Apple, Banana, Mango"</code> back into an array.</p>
</li>
<li><p>Sort fruits alphabetically and then reverse the order.</p>
</li>
<li><p>Create a new array of fruits with <code>" Juice"</code> added to each name.</p>
</li>
<li><p>Create a new array of fruits that <strong>start with A or B</strong>.</p>
</li>
<li><p>Count total number of letters in all fruit names combined.</p>
</li>
<li><p>Find the <strong>first fruit</strong> that starts with <code>"O"</code>.</p>
</li>
<li><p>Stop looping once you find <code>"Mango"</code> and print only fruits before it.</p>
</li>
</ol>
<h3 id="heading-closing-note">🍎 <strong>Closing Note</strong></h3>
<p>And that wraps up <strong>Day 3 — Arrays &amp; Loops!</strong><br />You’ve learned how to store, organize, and move through data effortlessly — from stacking fruits in baskets to looping through them like a pro. These are the real building blocks of logic in JavaScript.</p>
<p>Every time you <code>push</code>, <code>pop</code>, or loop through an array, you’re training your brain to think like a developer step by step, pattern by pattern. Keep practising these challenges until they feel natural, because tomorrow’s JavaScript magic will build right on top of this foundation.</p>
<blockquote>
<p>“<strong>Next stop: Smart Loops and Advanced Array Methods 🚀</strong>”</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Day 2 — Functions and Arrow Functions Explained Like a Pro”]]></title><description><![CDATA[What is a function ?
Every time you find yourself repeating code, JavaScript whispers, “There’s a smarter way.”That smarter way is called a function.
Functions are reusable blocks of code that perform a specific taskyou can define once and use anywhe...]]></description><link>https://tirandazadiba.hashnode.dev/day-2-functions-and-arrow-functions-explained-like-a-pro</link><guid isPermaLink="true">https://tirandazadiba.hashnode.dev/day-2-functions-and-arrow-functions-explained-like-a-pro</guid><category><![CDATA[learn JavaScript in 7 Days]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[learn javascript]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[earn JavaScript from scratch JavaScript basics for beginners Advanced JavaScript techniques JavaScript projects for practice Mastering JavaScript Zero to hero with JavaScript JavaScript for web development JavaScript programming guide Comprehensive JavaScript course JavaScript tips and tricks JavaScript best practices.]]></category><dc:creator><![CDATA[Adiba Tirandaz]]></dc:creator><pubDate>Mon, 10 Nov 2025 09:39:47 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-is-a-function">What is a function ?</h2>
<p>Every time you find yourself repeating code, JavaScript whispers, “There’s a smarter way.”<br />That smarter way is called a <strong>function</strong>.</p>
<p>Functions are reusable blocks of code that perform a specific task<br />you can <strong>define once</strong> and <strong>use anywhere</strong>.</p>
<blockquote>
<p>“A function is a shortcut from problem to solution — write once, use forever.”</p>
</blockquote>
<p>Think of your JavaScript program as a giant factory.<br />Inside it, you have <strong>machines</strong> (functions).</p>
<p>Each machine:</p>
<ul>
<li><p>Takes some <strong>raw materials</strong> (inputs or parameters).</p>
</li>
<li><p>Does some <strong>processing</strong> (the logic inside).</p>
</li>
<li><p>And gives you a <strong>finished product</strong> (the return value).</p>
</li>
</ul>
<p>You press a button (call the function) the machine starts working.<br />You get the same predictable result every time you feed it the same input.<br />That’s the beauty of it: <strong>a function is a reusable logic machine</strong>.</p>
<h3 id="heading-1-function-declaration">🔹 1. Function Declaration</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">'Hi '</span> + name;
}

<span class="hljs-built_in">console</span>.log(greet(<span class="hljs-string">'Adiba'</span>)); <span class="hljs-comment">// Hi Adiba</span>
</code></pre>
<ul>
<li><p>Has a name (<code>greet</code>)</p>
</li>
<li><p>Takes parameters (<code>name</code>)</p>
</li>
<li><p>Returns a value</p>
</li>
<li><p>Must be called to run</p>
</li>
</ul>
<h3 id="heading-2-function-expression">🔹 2. Function Expression</h3>
<p>Functions can be stored in variables too:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> greet = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">'Hello '</span> + name;
};
</code></pre>
<ul>
<li><p>Anonymous (no name)</p>
</li>
<li><p>Useful when passing around functions or callbacks</p>
</li>
</ul>
<h3 id="heading-3-arrow-functions-es6">🔹 3. Arrow Functions (ES6)</h3>
<p>Introduced in ES6, arrow functions make code shorter and cleaner.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> greet = <span class="hljs-function">(<span class="hljs-params">name</span>) =&gt;</span> <span class="hljs-string">'Hello '</span> + name;
</code></pre>
<ul>
<li><p>No <code>function</code> keyword</p>
</li>
<li><p><code>return</code> and <code>{}</code> can be omitted for one-line functions</p>
</li>
<li><p>Great for callbacks and modern Angular/React code</p>
</li>
</ul>
<h3 id="heading-4-default-parameters">🔹 4. Default Parameters</h3>
<p>Give parameters a default value:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params">name = <span class="hljs-string">'Guest'</span></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">'Hello '</span> + name;
}
</code></pre>
<h3 id="heading-5-returning-objects">🔹 5. Returning Objects</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> getUser = <span class="hljs-function">(<span class="hljs-params">name, age</span>) =&gt;</span> ({
  name,
  age,
  <span class="hljs-attr">info</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span> is <span class="hljs-subst">${age}</span> years old.`</span>,
});

<span class="hljs-built_in">console</span>.log(getUser(<span class="hljs-string">'Adiba'</span>, <span class="hljs-number">25</span>));
</code></pre>
<h3 id="heading-6-practical-example-full-user-info">🔹 6. Practical Example — Full User Info</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> getUserInfo = <span class="hljs-function">(<span class="hljs-params">name, age, city</span>) =&gt;</span>
  <span class="hljs-string">`<span class="hljs-subst">${name}</span>, <span class="hljs-subst">${age}</span>, lives in <span class="hljs-subst">${city}</span>.`</span>;

<span class="hljs-built_in">console</span>.log(getUserInfo(<span class="hljs-string">'Adiba'</span>, <span class="hljs-number">25</span>, <span class="hljs-string">'Pune'</span>));
</code></pre>
<h3 id="heading-key-takeaways">🧩 Key Takeaways</h3>
<ul>
<li><p>Functions = reusable code shortcuts</p>
</li>
<li><p><code>function</code> and <code>=&gt;</code> both define them</p>
</li>
<li><p>Always return what you need</p>
</li>
<li><p>Arrow functions are best for compact logic</p>
</li>
</ul>
<h3 id="heading-why-use-functions">🧠 Why Use Functions?</h3>
<ul>
<li><p>Avoid repeating code (DRY = Don’t Repeat Yourself)</p>
</li>
<li><p>Organize logic into small, testable chunks</p>
</li>
<li><p>Improve readability</p>
</li>
<li><p>Make debugging and updates easier</p>
</li>
</ul>
<h3 id="heading-challenge-time-hands-on-practice">🧩 Challenge Time (Hands-On Practice)</h3>
<p>Let’s make this an actual hour-long session with these mini-tasks:</p>
<p><strong>Simple Function:</strong> Create <code>add(a, b)</code> that returns their sum.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">add</span>(<span class="hljs-params">a, b</span>) </span>{
  <span class="hljs-keyword">return</span> a + b;
}

<span class="hljs-built_in">console</span>.log(add(<span class="hljs-number">12</span>, <span class="hljs-number">25</span>)); <span class="hljs-comment">// ✅ 37</span>
</code></pre>
<p><strong>Arrow Rewrite:</strong> Convert <code>add()</code> to arrow syntax.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> add = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span>  a + b;
<span class="hljs-built_in">console</span>.log(add(<span class="hljs-number">12</span>, <span class="hljs-number">25</span>)); <span class="hljs-comment">// 37</span>
</code></pre>
<p><strong>Greeting Function:</strong> Add a default name.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params">name = <span class="hljs-string">'Guest'</span></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`Hello, <span class="hljs-subst">${name}</span>!`</span>;
}

<span class="hljs-built_in">console</span>.log(greet(<span class="hljs-string">'Adiba'</span>)); <span class="hljs-comment">// Hello, Adiba!</span>
<span class="hljs-built_in">console</span>.log(greet());        <span class="hljs-comment">// Hello, Guest!</span>
</code></pre>
<p><strong>User Card:</strong> Create a function that returns a formatted user card (like a business card string).</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">userCard</span>(<span class="hljs-params">name, role, city</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-string">`
  Name: <span class="hljs-subst">${name}</span>
  Role: <span class="hljs-subst">${role}</span>
  City: <span class="hljs-subst">${city}</span>
  `</span>;
}

<span class="hljs-built_in">console</span>.log(userCard(<span class="hljs-string">'Adiba'</span>, <span class="hljs-string">'Frontend Developer'</span>, <span class="hljs-string">'Pune'</span>));
</code></pre>
<p><strong>Compare Age:</strong> Create a function <code>compareAges(user1, user2)</code> that returns who’s older.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">compareAges</span>(<span class="hljs-params">user1, user2</span>) </span>{
  <span class="hljs-keyword">if</span> (user1.age &gt; user2.age) {
    <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${user1.name}</span> is older than <span class="hljs-subst">${user2.name}</span>.`</span>;
  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (user1.age &lt; user2.age) {
    <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${user2.name}</span> is older than <span class="hljs-subst">${user1.name}</span>.`</span>;
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${user1.name}</span> and <span class="hljs-subst">${user2.name}</span> are the same age.`</span>;
  }
}

<span class="hljs-keyword">const</span> userA = { <span class="hljs-attr">name</span>: <span class="hljs-string">'Adiba'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">25</span> };
<span class="hljs-keyword">const</span> userB = { <span class="hljs-attr">name</span>: <span class="hljs-string">'Riya'</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">27</span> };

<span class="hljs-built_in">console</span>.log(compareAges(userA, userB));
</code></pre>
<h3 id="heading-closing-thought">✨ Closing Thought</h3>
<p>Functions are like your <strong>team of mini-robots</strong> — each built for one task.<br />Train them once, and they’ll keep working tirelessly while you move on to bigger ideas.</p>
]]></content:encoded></item><item><title><![CDATA[Day 1: JavaScript Variables and Data Types Explained Simply]]></title><description><![CDATA[What is JavaScript?
JavaScript (JS) is a computer language that makes web pages interactive.It helps you add things like buttons that work, forms that respond, and animations that move.While HTML builds the structure and CSS makes it look good, JavaS...]]></description><link>https://tirandazadiba.hashnode.dev/javascript-day-1-variables-and-data-types-explained-simply</link><guid isPermaLink="true">https://tirandazadiba.hashnode.dev/javascript-day-1-variables-and-data-types-explained-simply</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[frontend]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[7-Day Crash Course]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Adiba Tirandaz]]></dc:creator><pubDate>Sun, 09 Nov 2025 13:16:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1762695075069/b11e7925-6d3b-43b5-b93a-f1e84ee72baf.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-javascript"><strong>What is JavaScript?</strong></h2>
<p><strong>JavaScript (JS)</strong> is a computer language that makes web pages <strong>interactive</strong>.<br />It helps you add things like <strong>buttons that work</strong>, <strong>forms that respond</strong>, and <strong>animations that move</strong>.<br />While <strong>HTML</strong> builds the structure and <strong>CSS</strong> makes it look good, <strong>JavaScript</strong> makes it <strong>come alive</strong>.</p>
<p><strong>Example</strong></p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span> Click me! <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span> <span class="hljs-comment">&lt;!-- Without JavaScript --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"alert('Hello, World!')"</span>&gt;</span> Click me!<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span> <span class="hljs-comment">&lt;!-- With JavaScript --&gt;</span>
</code></pre>
<p>JavaScript is what turns a static webpage into an interactive experience from buttons and popups to real-time apps and games.</p>
<h2 id="heading-variable"><strong>Variable</strong></h2>
<p>A <strong>variable</strong> is like a container that holds data.<br />You can <strong>store</strong>, <strong>use</strong>, and <strong>change</strong> values inside it anytime.</p>
<p>Variables in JavaScript are like <strong>water bottles</strong> they hold something, but not all bottles behave the same.</p>
<p><strong><em>Var :</em></strong> The Leaky Bottle</p>
<p>You can pour out the water, fill it again, and even spill it everywhere.<br />It doesn’t care where it leaks, that’s why it’s not safe to use anymore.</p>
<p><code>var</code> is the <strong>old way</strong> to declare variables in JavaScript.<br />You can change its value and even re-declare it.<br />It does <strong>not follow block rules</strong>, so it can leak outside <code>{ }</code>.</p>
<p><strong><em>Example :</em></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> bottle = <span class="hljs-string">"Water"</span>;
bottle = <span class="hljs-string">"Juice"</span>;
<span class="hljs-built_in">console</span>.log(bottle); <span class="hljs-comment">// Juice</span>

<span class="hljs-keyword">var</span> city = <span class="hljs-string">"Pune"</span>;
<span class="hljs-keyword">var</span> city = <span class="hljs-string">"Delhi"</span>; <span class="hljs-comment">// ✅ works</span>
<span class="hljs-built_in">console</span>.log(city); <span class="hljs-comment">// Delhi</span>
</code></pre>
<p><strong><em>let :</em></strong> The Refillable Bottle</p>
<p>You can change what’s inside, but it stays <strong>sealed inside one place</strong> (your block).<br />If you put it somewhere else, it won’t spill over.</p>
<p><code>let</code> is the <strong>modern way</strong> to declare variables.<br />You can <strong>change</strong> its value, but <strong>cannot re-declare</strong> it in the same block.<br />It follows <strong>block scope</strong>, meaning it stays inside <code>{ }</code>.</p>
<p><strong><em>Example :</em></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> drink = <span class="hljs-string">"Coffee"</span>;
drink = <span class="hljs-string">"Tea"</span>;
<span class="hljs-built_in">console</span>.log(drink); <span class="hljs-comment">// Tea</span>

<span class="hljs-keyword">let</span> age = <span class="hljs-number">25</span>;
age = <span class="hljs-number">26</span>; <span class="hljs-comment">// ✅ works</span>
<span class="hljs-keyword">let</span> age = <span class="hljs-number">30</span>; <span class="hljs-comment">// ❌ Error</span>
</code></pre>
<p><strong><em>const :</em></strong> The Sealed Bottle</p>
<p>Once sealed, you <strong>can’t change</strong> what’s inside.<br />It’s frozen — permanent — like bottled soda you can’t refill.</p>
<p><code>const</code> is used when you don’t want the value to change.<br />You <strong>must assign</strong> a value when declaring it, and it can’t be changed or re-declared.</p>
<p><strong><em>Example :</em></strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> soda = <span class="hljs-string">"Coke"</span>;
soda = <span class="hljs-string">"Pepsi"</span>; <span class="hljs-comment">// ❌ Error</span>

<span class="hljs-keyword">const</span> country = <span class="hljs-string">"India"</span>;
country = <span class="hljs-string">"USA"</span>; <span class="hljs-comment">// ❌ Error</span>
</code></pre>
<p><strong>In short:</strong></p>
<ul>
<li><p>Use <code>let</code> for changing values</p>
</li>
<li><p>Use <code>const</code> for fixed values</p>
</li>
<li><p>Avoid <code>var</code> in modern JavaScript</p>
</li>
</ul>
<blockquote>
<h3 id="heading-var-leaks-let-keeps-const-locks"><code>var</code> leaks, <code>let</code> keeps, <code>const</code> locks.</h3>
</blockquote>
<h2 id="heading-data-types-in-javascript"><strong>Data Types in JavaScript</strong></h2>
<p>A <strong>data type</strong> means <em>what kind of value</em> a variable holds.<br />Think of it like “what’s inside your box.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Data-Type</strong></td><td><strong>Description</strong></td><td><strong>Example</strong></td></tr>
</thead>
<tbody>
<tr>
<td>String</td><td>Anything inside <code>" "</code> or <code>' '</code> is a string.</td><td><code>let name = "Adiba";</code></td></tr>
<tr>
<td>Number</td><td>All numbers</td><td><code>let age = 25; let price = 99.99;</code></td></tr>
<tr>
<td>Boolean</td><td>true or false</td><td><code>let isOnline = true; let isAdmin = false;</code></td></tr>
<tr>
<td>Array</td><td>list of values</td><td><code>let skills = ["HTML", "CSS", "JavaScript"];</code></td></tr>
<tr>
<td>Object</td><td>data with labels</td><td><code>let user = { name: "Adiba", city: "Pune", age: 25 };</code></td></tr>
<tr>
<td>Undefined</td><td>declared but not given a value</td><td><code>let country;</code></td></tr>
<tr>
<td>Null</td><td>empty on purpose</td><td><code>let car = null;</code></td></tr>
</tbody>
</table>
</div><h2 id="heading-task">🧠 <strong>Task</strong></h2>
<p><strong>1) Write a short script that prints:</strong></p>
<ul>
<li><p>One leaky bottle (var)</p>
</li>
<li><p>One refillable bottle (let)</p>
</li>
<li><p>One sealed bottle (const)</p>
</li>
</ul>
<p>Then change their values and <strong>observe what happens</strong> in the console.</p>
<p><strong>2) Make one variable for each data type and print all of them in one console statement.<br />Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(name, age, isOnline, skills, user, country, car);
</code></pre>
<h2 id="heading-coming-up-next">🚀 Coming Up Next</h2>
<p>Tomorrow → <strong>Day 2: Functions and Arrow Functions</strong><br />We’ll teach JavaScript to <em>think and repeat actions</em> with reusable code.</p>
]]></content:encoded></item></channel></rss>