<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gurnoor Singh on Medium]]></title>
        <description><![CDATA[Stories by Gurnoor Singh on Medium]]></description>
        <link>https://medium.com/@singhgurnoor080?source=rss-5947c9590744------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xiiNMcRPIrozPmoR</url>
            <title>Stories by Gurnoor Singh on Medium</title>
            <link>https://medium.com/@singhgurnoor080?source=rss-5947c9590744------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:22:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@singhgurnoor080/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[In this post, we’ll break down React in the most intuitive way — by contrasting it with vanilla…]]></title>
            <link>https://medium.com/@singhgurnoor080/in-this-post-well-break-down-react-in-the-most-intuitive-way-by-contrasting-it-with-vanilla-90caf7005024?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/90caf7005024</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 04:25:58 GMT</pubDate>
            <atom:updated>2025-07-29T04:25:58.562Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Deep Dive: Understanding React Through Simple Examples</h3><p>In this post, we’ll break down React in the most intuitive way — <strong>by contrasting it with vanilla JavaScript</strong>. If you’ve ever found React confusing or wondered <em>why we even need it</em>, this guide is for you.</p><h3>🧠 What We’ll Learn Today</h3><p>We’ll unpack React using everyday code and examples. Along the way, you’ll learn some important frontend jargon:</p><ul><li>JSX</li><li>class vs className</li><li>Static vs Dynamic Websites</li><li>Components</li><li>State</li><li>Re-rendering</li></ul><p>Let’s get started!</p><h3>🧱 Static vs Dynamic Websites</h3><p><strong>Static websites</strong> are simple — just plain HTML, CSS, and maybe a sprinkle of JS. They show the same content to everyone.</p><p>But if you want your app to <em>react</em> (pun intended) to user interactions — like updating a counter, toggling themes, submitting forms — <strong>you’re building a dynamic website</strong>.</p><p>That’s where things get tricky in vanilla JS.</p><h3>👇 Traditional DOM Manipulation</h3><p>Let’s say we want to create a button that increases a counter each time it’s clicked.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;button onclick=&quot;onButtonPress()&quot; id=&quot;btn&quot;&gt;Counter 0&lt;/button&gt;</pre><pre>    &lt;script&gt;<br>      function onButtonPress() {<br>        const currentValue = document.getElementById(&quot;btn&quot;).innerHTML;<br>        const currentCounter = currentValue.split(&quot; &quot;)[1];<br>        const newCounter = parseInt(currentCounter) + 1;<br>        document.getElementById(&quot;btn&quot;).innerHTML = &quot;Counter &quot; + newCounter;<br>      }<br>    &lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><h3>🧨 Problems with this approach:</h3><ol><li>You have to <strong>manually fetch and update the DOM</strong> every time something changes.</li><li>For <strong>larger apps</strong>, this becomes error-prone and unmanageable.</li><li>As UI complexity grows, this pattern doesn’t scale well.</li></ol><h3>🤔 Why Do You Need React?</h3><p>You <em>don’t</em> need React for static websites.</p><p>But for dynamic websites with frequent UI updates, <strong>React simplifies everything</strong>.</p><p>Think of it this way:</p><blockquote><em>✨ </em><strong><em>React is just an easier way to write HTML/CSS/JS.</em></strong><em><br> Just like how ChatGPT is an easier way to write code, React makes it easier to create dynamic UIs.</em></blockquote><h3>🧪 React-Like Logic in Plain JavaScript</h3><p>Let’s manually mimic a basic React pattern using <strong>state and components</strong>:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;div id=&quot;buttonParent&quot;&gt;&lt;/div&gt;</pre><pre>    &lt;script&gt;<br>      let state = { count: 0 };</pre><pre>      function onButtonPress() {<br>        state.count++;<br>        buttonComponentReRender();<br>      }</pre><pre>      function buttonComponent(count) {<br>        const button = document.createElement(&quot;button&quot;);<br>        button.innerHTML = &quot;Counter &quot; + count;<br>        button.setAttribute(&quot;onclick&quot;, `onButtonPress()`);<br>        return button;<br>      }</pre><pre>      function buttonComponentReRender() {<br>        const parent = document.getElementById(&quot;buttonParent&quot;);<br>        parent.innerHTML = &quot;&quot;; // Clear old<br>        parent.appendChild(buttonComponent(state.count)); // Render new<br>      }</pre><pre>      buttonComponentReRender();<br>    &lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><h3>This is essentially what React does internally!</h3><h3>⚛️ Enter React</h3><p>Now imagine instead of writing 50+ lines of repetitive DOM logic, you could do this:</p><pre>import { useState } from &#39;react&#39;;</pre><pre>function Counter() {<br>  const [count, setCount] = useState(0);</pre><pre>  return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      Counter {count}<br>    &lt;/button&gt;<br>  );<br>}</pre><p>Boom. 6 lines of code. Clean, declarative, and reactive.</p><h3>🧩 React Jargon Made Simple</h3><h3>✅ JSX</h3><p>JSX stands for <strong>JavaScript XML</strong>. It allows you to write HTML-like syntax <em>inside JavaScript</em>.</p><pre>const element = &lt;h1&gt;Hello, world!&lt;/h1&gt;;</pre><p>It may look like HTML, but it’s JavaScript under the hood. Babel (a compiler) converts this into regular JS calls like:</p><pre>React.createElement(&quot;h1&quot;, null, &quot;Hello, world!&quot;);</pre><h3>✅ Components</h3><p>A <strong>component</strong> is a reusable piece of UI — like a button, navbar, or card.</p><pre>function Welcome() {<br>  return &lt;h1&gt;Welcome to React!&lt;/h1&gt;;<br>}</pre><h3>✅ State</h3><p><strong>State</strong> is data that can change over time. Think of it as memory for your component.</p><pre>const [count, setCount] = useState(0);</pre><p>When count changes, the component <strong>re-renders</strong> automatically.</p><h3>✅ Re-rendering</h3><p>Whenever state updates, React <strong>automatically updates the DOM</strong> to reflect the new state. You don’t have to manually manipulate document.getElementById() anymore.</p><h3>🚀 Why React Wins</h3><p>FeatureVanilla JSReactDOM manipulationManualAutomatic via virtual DOMCode reuseLimitedEasy with componentsScalabilityHard to manageVery scalableDeveloper experienceVerboseClean, declarative, fun</p><h3>🛠️ How to Get Started</h3><p>Want to try React?</p><p>Use <strong>Vite</strong> to scaffold a modern React app quickly:</p><pre>npm create vite@latest</pre><p>Choose React, then JavaScript or TypeScript, and you&#39;re good to go.</p><h3>🧵 Final Thoughts</h3><p>React isn’t magic. It’s just a smarter way to write HTML, CSS, and JS.</p><ul><li>For small static pages → Stick to plain HTML/CSS.</li><li>For dynamic, interactive UIs → React makes your life easier.</li></ul><p>The real power of React lies in <strong>stateful, component-based thinking</strong>. Once you wrap your head around that, everything else will start to click.</p><p>✍️ <em>If this helped simplify React for you, leave a clap or drop a comment. I’ll be deep-diving into hooks, props, and routing in the next part!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90caf7005024" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Practical MongoDB Guide for Beginners (With a Full-Stack Example)]]></title>
            <link>https://medium.com/@singhgurnoor080/a-practical-mongodb-guide-for-beginners-with-a-full-stack-example-044a0640ce6c?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/044a0640ce6c</guid>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Thu, 24 Jul 2025 12:28:09 GMT</pubDate>
            <atom:updated>2025-07-24T12:28:09.662Z</atom:updated>
            <content:encoded><![CDATA[<p>Databases are organized collections of data that are structured to enable efficient storage, retrieval, and management of information.</p><p>Whenever you create a full stack app, you need to persist data in databases.</p><p>For example:</p><ul><li>User information</li><li>TODOs of your todo app</li><li>Posts for Facebook</li><li>Tweets for Twitter</li></ul><h3>Types of Databases</h3><ul><li><strong>Relational Databases</strong>: Use tables to store data and relationships (e.g., MySQL, PostgreSQL).</li><li><strong>NoSQL Databases</strong>: Designed for more flexible data models (e.g., MongoDB).</li><li><strong>Graph Databases</strong>: Store data in nodes and edges (e.g., Neo4j).</li><li><strong>Vector Databases</strong>: Used in ML to store data as embeddings.</li></ul><p>In this guide, we’ll dive deep into MongoDB, a popular NoSQL database.</p><h3>Why MongoDB?</h3><p>MongoDB uses a document-oriented approach. Instead of tables and rows, it stores data in flexible, JSON-like documents.</p><h3>Key Features</h3><ul><li><strong>Schema Flexibility</strong>: No fixed structure required</li><li><strong>Scalability</strong>: Easy to scale horizontally</li><li><strong>BSON Format</strong>: Binary version of JSON, optimized for speed</li></ul><h3>Step 1: Creating a Free MongoDB Server</h3><ol><li>Signup at <a href="https://cloud.mongodb.com/">https://cloud.mongodb.com/</a></li><li>Create a free M0 cluster</li><li>Create a new database user (username + password)</li><li>Allow access from your current IP</li><li>Copy the connection string (you’ll need it soon)</li><li>Install MongoDB Compass (optional GUI for your database)</li></ol><h3>Step 2: Seeding Data in the DB</h3><ol><li>Create a database named todo-app</li><li>Add two collections: users and todos</li><li>Seed sample documents manually in MongoDB Compass</li></ol><h3>Step 3: Connecting Full Stack App to MongoDB</h3><h3>Initialize a Node.js Project</h3><pre>npm init -y</pre><h3>Install Dependencies</h3><pre>npm install express mongoose jsonwebtoken</pre><h3>Connect to MongoDB (index.js)</h3><p>const mongoose = require(“mongoose”);<br>mongoose.connect(“&lt;your_connection_string_here&gt;”);</p><h3>Step 4: Defining Schema with Mongoose</h3><h3>db.js</h3><p>const mongoose = require(“mongoose”);<br>const Schema = mongoose.Schema;<br>const ObjectId = Schema.ObjectId;</p><p>const User = new Schema({<br> name: String,<br> email: { type: String, unique: true },<br> password: String<br>});</p><p>const Todo = new Schema({<br> userId: ObjectId,<br> title: String,<br> done: Boolean<br>});</p><p>const UserModel = mongoose.model(‘users’, User);<br>const TodoModel = mongoose.model(‘todos’, Todo);</p><p>module.exports = {<br> UserModel,<br> TodoModel<br>};</p><h3>Step 5: CRUD Operations in Express</h3><h3>Basic Express Server (index.js)</h3><pre>const express = require(&quot;express&quot;);<br>const { UserModel, TodoModel } = require(&quot;./db&quot;);<br>const jwt = require(&quot;jsonwebtoken&quot;);<br>const app = express();<br>const JWT_SECRET = &quot;s3cret&quot;;</pre><pre>app.use(express.json());</pre><pre>app.post(&quot;/signup&quot;, async (req, res) =&gt; {<br>  const { email, password, name } = req.body;<br>  await UserModel.create({ email, password, name });<br>  res.json({ message: &quot;You are signed up&quot; });<br>});</pre><pre>app.post(&quot;/signin&quot;, async (req, res) =&gt; {<br>  const { email, password } = req.body;<br>  const response = await UserModel.findOne({ email, password });</pre><pre>  if (response) {<br>    const token = jwt.sign({ id: response._id.toString() }, JWT_SECRET);<br>    res.json({ token });<br>  } else {<br>    res.status(403).json({ message: &quot;Incorrect creds&quot; });<br>  }<br>});</pre><pre>// Auth Middleware<br>function auth(req, res, next) {<br>  const token = req.headers.authorization;<br>  try {<br>    const decoded = jwt.verify(token, JWT_SECRET);<br>    req.userId = decoded.id;<br>    next();<br>  } catch (err) {<br>    res.status(403).json({ message: &quot;Invalid token&quot; });<br>  }<br>}</pre><pre>app.post(&quot;/todo&quot;, auth, async (req, res) =&gt; {<br>  const { title } = req.body;<br>  await TodoModel.create({<br>    userId: req.userId,<br>    title,<br>    done: false<br>  });<br>  res.json({ message: &quot;Todo created&quot; });<br>});</pre><pre>app.get(&quot;/todos&quot;, auth, async (req, res) =&gt; {<br>  const todos = await TodoModel.find({ userId: req.userId });<br>  res.json({ todos });<br>});</pre><pre>app.listen(3000, () =&gt; console.log(&quot;Server running on port 3000&quot;));</pre><h3>Step 6: Testing Your App (Use Postman)</h3><h3>1. Signup</h3><p>Send a POST request to /signup with:</p><pre>{<br>  &quot;name&quot;: &quot;John&quot;,<br>  &quot;email&quot;: &quot;john@example.com&quot;,<br>  &quot;password&quot;: &quot;123456&quot;<br>}</pre><h3>2. Signin</h3><p>Send a POST request to /signin and save the token</p><h3>3. Create Todo</h3><p>Send a POST request to /todo with Authorization header:</p><pre>Authorization: &lt;token&gt;</pre><p>Body:</p><pre>{<br>  &quot;title&quot;: &quot;Finish MongoDB article&quot;<br>}</pre><h3>4. Get Todos</h3><p>Send a GET request to /todos with Authorization header.</p><h3>Improvements to Make</h3><ol><li><strong>Hash passwords</strong> using bcrypt</li><li><strong>Add validation</strong> for email and password</li><li><strong>Handle errors</strong> like duplicate emails</li><li><strong>Add timestamps</strong> for todos</li><li><strong>Mark todos as complete</strong> with a PATCH route</li><li><strong>Use environment variables</strong> for secrets and DB URLs</li></ol><h3>Final Thoughts</h3><p>MongoDB is beginner-friendly, scalable, and perfect for JavaScript developers. Once you understand the CRUD basics and how to connect your full-stack app using Mongoose, you’re ready to build real-world apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=044a0640ce6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Promises — The Ultimate Beginner’s Guide]]></title>
            <link>https://medium.com/@singhgurnoor080/javascript-promises-the-ultimate-beginners-guide-ee965c0f167f?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee965c0f167f</guid>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[mern-stack]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Sun, 01 Jun 2025 02:32:30 GMT</pubDate>
            <atom:updated>2025-06-01T02:32:30.341Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript Promises — The Ultimate Beginner’s Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hg8ynt0LX24dEYtDClh4Lw.png" /></figure><p>If you’ve ever worked with APIs, timers, or file operations in JavaScript, you’ve probably come across the word: <strong>Promise</strong>.</p><blockquote><em>A </em><strong><em>Promise</em></strong><em> is JavaScript’s way of saying:<br> </em>“Hey, I’m doing something right now. I’ll get back to you later — either with the result, or with an error.”</blockquote><h3>🔁 The Problem Before Promises: Callbacks</h3><p>Let’s say you want to read a file and log its content:</p><pre>fs.readFile(&quot;a.txt&quot;, &quot;utf-8&quot;, function (err, data) {<br>  if (err) {<br>    console.log(&quot;Error reading file&quot;);<br>  } else {<br>    console.log(data);<br>  }<br>});</pre><p>Works fine, right? But what if you want to:</p><ul><li>Read a file</li><li>Trim it</li><li>Save it</li><li>Notify the user</li></ul><p>You’ll nest callbacks within callbacks… leading to <strong>callback hell</strong>:</p><pre>step1(function () {<br>  step2(function () {<br>    step3(function () {<br>      step4();<br>    });<br>  });<br>});</pre><p>It’s messy. Hard to read. Harder to maintain. 😣</p><h3>✅ Promises to the Rescue</h3><h3>💡 What is a Promise?</h3><blockquote><em>A </em><strong><em>Promise</em></strong><em> is an object that represents a value that may be available now, or in the future, or never.</em></blockquote><p>It has <strong>3 states</strong>:</p><p>State Meaning <strong>Pending</strong> The async operation hasn’t completed yet <strong>Fulfilled</strong> The operation completed successfully <strong>Rejected</strong> The operation failed (e.g., an error occurred)</p><h3>📦 Creating a Promise</h3><p>Let’s build a simple promise from scratch:</p><pre>const myPromise = new Promise(function (resolve, reject) {<br>  const success = true;</pre><pre>  if (success) {<br>    resolve(&quot;Success! 🎉&quot;);<br>  } else {<br>    reject(&quot;Something went wrong 😢&quot;);<br>  }<br>});</pre><p>You can use:</p><ul><li>resolve(value) — when things go right ✅</li><li>reject(error) — when things go wrong ❌</li></ul><h3>🔄 Using .then() and .catch()</h3><p>Once you have a promise, here’s how you consume it:</p><pre>myPromise<br>  .then(function (message) {<br>    console.log(&quot;Resolved:&quot;, message);<br>  })<br>  .catch(function (error) {<br>    console.log(&quot;Rejected:&quot;, error);<br>  });</pre><h3>🧪 Real Example: Timer</h3><pre>function wait(ms) {<br>  return new Promise(function (resolve) {<br>    setTimeout(resolve, ms);<br>  });<br>}</pre><pre>wait(2000).then(() =&gt; {<br>  console.log(&quot;2 seconds passed&quot;);<br>});</pre><h3>🌌 Chaining Promises</h3><p>Promises can be <strong>chained</strong>, meaning each .then() passes its result to the next one:</p><pre>wait(1000)<br>  .then(() =&gt; {<br>    console.log(&quot;Step 1: after 1 sec&quot;);<br>    return wait(2000);<br>  })<br>  .then(() =&gt; {<br>    console.log(&quot;Step 2: after 2 sec&quot;);<br>    return wait(3000);<br>  })<br>  .then(() =&gt; {<br>    console.log(&quot;Step 3: after 3 sec&quot;);<br>  });</pre><p>No nesting. Much cleaner!</p><h3>❗ Handling Errors with .catch()</h3><p>If anything goes wrong in any .then(), .catch() will handle it.</p><pre>new Promise((resolve, reject) =&gt; {<br>  reject(&quot;Oops&quot;);<br>})<br>  .then(() =&gt; console.log(&quot;Will not run&quot;))<br>  .catch((err) =&gt; console.log(&quot;Caught error:&quot;, err));</pre><h3>🔁 Promise.resolve and Promise.reject</h3><p>Quick ways to create a promise:</p><pre>Promise.resolve(&quot;Instant success&quot;).then(console.log);<br>Promise.reject(&quot;Instant fail&quot;).catch(console.log);</pre><h3>🚧 Turning Callbacks into Promises</h3><p>Let’s convert a Node-style callback function to a promise:</p><pre>const fs = require(&quot;fs&quot;);</pre><pre>function readFilePromise(filePath) {<br>  return new Promise((resolve, reject) =&gt; {<br>    fs.readFile(filePath, &quot;utf-8&quot;, (err, data) =&gt; {<br>      if (err) reject(err);<br>      else resolve(data);<br>    });<br>  });<br>}</pre><pre>readFilePromise(&quot;a.txt&quot;)<br>  .then((data) =&gt; console.log(&quot;Data:&quot;, data))<br>  .catch((err) =&gt; console.log(&quot;Error:&quot;, err));</pre><h3>🧙 Async/Await — The Cleanest Syntax</h3><p>Instead of chaining .then(), you can use async/await:</p><pre>function wait(ms) {<br>  return new Promise(resolve =&gt; setTimeout(resolve, ms));<br>}</pre><pre>async function run() {<br>  await wait(1000);<br>  console.log(&quot;Step 1&quot;);</pre><pre>  await wait(2000);<br>  console.log(&quot;Step 2&quot;);</pre><pre>  await wait(1000);<br>  console.log(&quot;Step 3&quot;);<br>}</pre><pre>run();</pre><p>💡 await only works inside async functions!</p><h3>🎯 Real-World: Promisifying File Cleanup</h3><h3>Callback version:</h3><pre>function cleanFile(filePath, cb) {<br>  fs.readFile(filePath, &quot;utf-8&quot;, function (err, data) {<br>    if (err) return cb(err);<br>    fs.writeFile(filePath, data.trim(), cb);<br>  });<br>}</pre><h3>Promise version:</h3><pre>function cleanFile(filePath) {<br>  return new Promise((resolve, reject) =&gt; {<br>    fs.readFile(filePath, &quot;utf-8&quot;, (err, data) =&gt; {<br>      if (err) reject(err);<br>      else {<br>        fs.writeFile(filePath, data.trim(), (err) =&gt; {<br>          if (err) reject(err);<br>          else resolve();<br>        });<br>      }<br>    });<br>  });<br>}</pre><p>Then:</p><pre>cleanFile(&quot;a.txt&quot;)<br>  .then(() =&gt; console.log(&quot;File cleaned&quot;))<br>  .catch((err) =&gt; console.log(&quot;Error:&quot;, err));</pre><p>Or use async/await:</p><pre>async function main() {<br>  try {<br>    await cleanFile(&quot;a.txt&quot;);<br>    console.log(&quot;File cleaned&quot;);<br>  } catch (err) {<br>    console.log(&quot;Error:&quot;, err);<br>  }<br>}</pre><pre>main();</pre><h3>🚨 Common Mistakes</h3><p>Mistake Why it’s a problem Not returning a promise in a .then() Causes .then() chain to break Forgetting await before a promise Code continues before the task finishes Using await outside async function Syntax error</p><h3>🧠 TL;DR — Promises Recap</h3><ul><li>Promises replace nested callbacks for better readability.</li><li>They represent future values and support chaining with .then().</li><li>Use .catch() for errors and async/await for cleaner async code.</li><li>You can wrap callback-based code with new Promise().</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee965c0f167f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Classes and Promises in JavaScript — A Beginner’s Guide]]></title>
            <link>https://medium.com/@singhgurnoor080/understanding-classes-and-promises-in-javascript-a-beginners-guide-1467eca683bb?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/1467eca683bb</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mern-stack]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Sat, 31 May 2025 03:53:57 GMT</pubDate>
            <atom:updated>2025-05-31T03:53:57.465Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Classes and Promises in JavaScript — A Beginner’s Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5WOffZyBfi77FQ7CHGnBxA.png" /></figure><p>JavaScript can feel like magic — but once you understand a few core concepts, it becomes a superpower. In this article, we’ll walk through:</p><ul><li>What are <strong>Classes</strong> and how to use them</li><li>How to work with <strong>Promises</strong></li><li>The problem of <strong>Callback Hell</strong></li><li>How to escape it using <strong>Async/Await</strong></li><li>Real-world async code examples like reading/writing files</li></ul><p>Let’s dive in! 🏊‍♂️</p><h3>📦 Primitive vs Complex Types</h3><p>Before we get to classes, let’s quickly understand types in JavaScript.</p><h3>👉 Primitive Types (Simple Values)</h3><ul><li>number</li><li>string</li><li>boolean</li></ul><pre>const score = 42;          // number<br>const name = &quot;Alice&quot;;      // string<br>const isCool = true;       // boolean</pre><h3>👉 Complex Types (Collections)</h3><ul><li>Object</li><li>Array</li></ul><pre>const person = { name: &quot;Alice&quot;, age: 30 }; // Object<br>const numbers = [1, 2, 3, 4];              // Array</pre><h3>🏗️ Classes in JavaScript</h3><p>Classes let us create <em>blueprints</em> for objects. Think of them like a mold you can use to make multiple items (objects) with the same structure and behavior.</p><pre>class Rectangle {<br>  constructor(width, height, color) {<br>    this.width = width;<br>    this.height = height;<br>    this.color = color;<br>  }</pre><pre>  area() {<br>    return this.width * this.height;<br>  }</pre><pre>  paint() {<br>    console.log(`Painting with color ${this.color}`);<br>  }<br>}</pre><pre>const rect = new Rectangle(2, 4);<br>console.log(rect.area()); // 8</pre><h3>🧩 Key Concepts</h3><p>Concept Description <strong>Constructor</strong> A special method that runs when you create a new object <strong>Methods</strong> Functions inside the class <strong>Properties</strong> Variables that belong to an object <strong>Inheritance</strong> A class can “extend” another class to reuse logic <strong>Static Methods</strong> Belong to the class itself, not its instances <strong>Getters/Setters</strong> Control how properties are read or changed</p><h3>📐 Inheritance in Action</h3><p>Let’s improve our Rectangle and Circle classes by using inheritance.</p><h3>🧱 Base Class — Shape</h3><pre>class Shape {<br>  constructor(color) {<br>    this.color = color;<br>  }</pre><pre>  paint() {<br>    console.log(`Painting with color ${this.color}`);<br>  }</pre><pre>  area() {<br>    throw new Error(&quot;Subclasses must implement the area method&quot;);<br>  }</pre><pre>  getDescription() {<br>    return `A shape with color ${this.color}`;<br>  }<br>}</pre><h3>📏 Rectangle Class</h3><pre>class Rectangle extends Shape {<br>  constructor(width, height, color) {<br>    super(color);<br>    this.width = width;<br>    this.height = height;<br>  }</pre><pre>  area() {<br>    return this.width * this.height;<br>  }</pre><pre>  getDescription() {<br>    return `A rectangle with width ${this.width}, height ${this.height}, and color ${this.color}`;<br>  }<br>}</pre><h3>⚪ Circle Class</h3><pre>class Circle extends Shape {<br>  constructor(radius, color) {<br>    super(color);<br>    this.radius = radius;<br>  }</pre><pre>  area() {<br>    return Math.PI * this.radius * this.radius;<br>  }</pre><pre>  getDescription() {<br>    return `A circle with radius ${this.radius} and color ${this.color}`;<br>  }<br>}</pre><h3>🔄 Promises: What, Why, and How</h3><p>A <strong>Promise</strong> is a JavaScript object that represents a task that will complete in the future.</p><pre>function setTimeoutPromisified(ms) {<br>  return new Promise((resolve) =&gt; setTimeout(resolve, ms));<br>}</pre><p>You use .then() to run code after the promise is resolved.</p><pre>setTimeoutPromisified(3000).then(() =&gt; {<br>  console.log(&quot;3 seconds have passed&quot;);<br>});</pre><h3>😵 Callback Hell</h3><p>This happens when you nest callbacks inside callbacks:</p><pre>setTimeout(() =&gt; {<br>  console.log(&quot;hi&quot;);<br>  setTimeout(() =&gt; {<br>    console.log(&quot;hello&quot;);<br>    setTimeout(() =&gt; {<br>      console.log(&quot;hello there&quot;);<br>    }, 5000);<br>  }, 3000);<br>}, 1000);</pre><h3>✅ Escaping Callback Hell</h3><h3>🔁 Cleaner Way with Functions</h3><pre>function step3() {<br>  console.log(&quot;hello there&quot;);<br>}</pre><pre>function step2() {<br>  console.log(&quot;hello&quot;);<br>  setTimeout(step3, 5000);<br>}</pre><pre>function step1() {<br>  console.log(&quot;hi&quot;);<br>  setTimeout(step2, 3000);<br>}</pre><pre>setTimeout(step1, 1000);</pre><h3>💡 Promises Version</h3><pre>function setTimeoutPromisified(ms) {<br>  return new Promise((resolve) =&gt; setTimeout(resolve, ms));<br>}</pre><pre>setTimeoutPromisified(1000)<br>  .then(() =&gt; {<br>    console.log(&quot;hi&quot;);<br>    return setTimeoutPromisified(3000);<br>  })<br>  .then(() =&gt; {<br>    console.log(&quot;hello&quot;);<br>    return setTimeoutPromisified(5000);<br>  })<br>  .then(() =&gt; {<br>    console.log(&quot;hello there&quot;);<br>  });</pre><h3>🧙 Async/Await Version (Super Clean)</h3><pre>async function solve() {<br>  await setTimeoutPromisified(1000);<br>  console.log(&quot;hi&quot;);</pre><pre>  await setTimeoutPromisified(3000);<br>  console.log(&quot;hello&quot;);</pre><pre>  await setTimeoutPromisified(5000);<br>  console.log(&quot;hello there&quot;);<br>}</pre><pre>solve();</pre><p>✅ <em>Much cleaner, easier to understand.</em></p><h3>🗂️ Maps in JS</h3><pre>const map = new Map();<br>map.set(&quot;name&quot;, &quot;Alice&quot;);<br>map.set(&quot;age&quot;, 30);</pre><pre>console.log(map.get(&quot;name&quot;)); // Alice</pre><h3>📅 Date Example</h3><pre>const now = new Date();<br>console.log(now.toISOString()); // 2025-05-30T...</pre><h3>📁 Real World: Read, Clean, Write a File</h3><h3>🧵 Callback Style</h3><pre>const fs = require(&quot;fs&quot;);</pre><pre>function cleanFile(filePath, cb) {<br>  fs.readFile(filePath, &quot;utf-8&quot;, function (err, data) {<br>    data = data.trim();<br>    fs.writeFile(filePath, data, function () {<br>      cb();<br>    });<br>  });<br>}</pre><pre>cleanFile(&quot;a.txt&quot;, () =&gt; console.log(&quot;file has been cleaned&quot;));</pre><h3>🧪 Promisified Version</h3><pre>const fs = require(&quot;fs&quot;);</pre><pre>function cleanFile(filePath) {<br>  return new Promise((resolve) =&gt; {<br>    fs.readFile(filePath, &quot;utf-8&quot;, (err, data) =&gt; {<br>      data = data.trim();<br>      fs.writeFile(filePath, data, () =&gt; {<br>        resolve();<br>      });<br>    });<br>  });<br>}</pre><pre>async function main() {<br>  await cleanFile(&quot;a.txt&quot;);<br>  console.log(&quot;Done cleaning file&quot;);<br>}</pre><pre>main();</pre><h3>🚨 Handling Errors: Callbacks vs Promises</h3><h3>❌ Error-first Callback</h3><pre>function afterDone(err, data) {<br>  if (err) {<br>    console.log(&quot;Error while reading file&quot;);<br>  } else {<br>    console.log(data);<br>  }<br>}</pre><pre>fs.readFile(&quot;a.txt&quot;, &quot;utf-8&quot;, afterDone);</pre><h3>✅ Promises with .catch()</h3><pre>function readFilePromisified(filePath) {<br>  return new Promise((resolve, reject) =&gt; {<br>    fs.readFile(filePath, &quot;utf-8&quot;, (err, data) =&gt; {<br>      if (err) reject(&quot;Error while reading file&quot;);<br>      else resolve(data);<br>    });<br>  });<br>}</pre><pre>readFilePromisified(&quot;a.txt&quot;)<br>  .then(console.log)<br>  .catch((err) =&gt; console.log(&quot;Error: &quot; + err));</pre><h3>🧠 Final Thoughts</h3><ul><li>✅ Use <strong>classes</strong> for reusable object patterns</li><li>✅ Use <strong>Promises</strong> to avoid messy async code</li><li>✅ Use <strong>async/await</strong> for clean, readable code</li><li>✅ Understand <strong>errors</strong> in both callbacks and promises</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1467eca683bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Functions and Asynchronous Code in JavaScript]]></title>
            <link>https://medium.com/@singhgurnoor080/understanding-functions-and-asynchronous-code-in-javascript-f577c43282b8?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/f577c43282b8</guid>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Fri, 30 May 2025 08:09:44 GMT</pubDate>
            <atom:updated>2025-05-30T08:09:44.620Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is one of the most popular programming languages in the world, powering everything from simple websites to complex server-side applications. In this post, we’ll dive into <strong>functions</strong>, <strong>synchronous and asynchronous execution</strong>, <strong>I/O vs CPU-bound tasks</strong>, and the <strong>JavaScript runtime architecture</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*upr36XVGhfnOiUm54h2UsQ.png" /></figure><h3>🧠 Normal Functions in JavaScript</h3><p>Here’s how to define a function in JS:</p><h3>➕ Find the sum of two numbers</h3><pre>function sum(a, b) {<br>	return a + b;<br>}</pre><pre>let ans = sum(2, 3);<br>console.log(ans); // 5</pre><h3>➕ Find the sum from 1 to n</h3><pre>function sum(n) {<br>	let ans = 0;<br>	for (let i = 1; i &lt;= n; i++) {<br>		ans += i;<br>	}<br>	return ans;<br>}</pre><pre>const result = sum(100);<br>console.log(result); // 5050</pre><h3>🧱 Synchronous Code</h3><p>Synchronous code is executed <strong>line-by-line</strong>, in the exact order it’s written. Each line must complete before the next starts.</p><pre>function sum(n) {<br>	let ans = 0;<br>	for (let i = 1; i &lt;= n; i++) {<br>		ans += i;<br>	}<br>	return ans;<br>}</pre><pre>const ans1 = sum(100);<br>console.log(ans1);</pre><pre>const ans2 = sum(1000);<br>console.log(ans2);</pre><pre>const ans3 = sum(10000);<br>console.log(ans3);</pre><h3>🔁 I/O Heavy Operations</h3><p><strong>I/O (Input/Output)</strong> operations deal with reading/writing data from/to external systems like disks, networks, or databases. These are slower than CPU-bound operations because they involve waiting for data transfer.</p><h3>Examples:</h3><ul><li>Reading files</li><li>Making HTTP requests</li><li>Starting timers or clocks</li></ul><h3>📦 Using require to Read Files</h3><p>To read files in Node.js:</p><pre>const fs = require(&quot;fs&quot;);</pre><pre>const contents = fs.readFileSync(&quot;a.txt&quot;, &quot;utf-8&quot;);<br>console.log(contents);</pre><p>To read multiple files:</p><pre>const fs = require(&quot;fs&quot;);</pre><pre>const contents1 = fs.readFileSync(&quot;a.txt&quot;, &quot;utf-8&quot;);<br>console.log(contents1);</pre><pre>const contents2 = fs.readFileSync(&quot;b.txt&quot;, &quot;utf-8&quot;);<br>console.log(contents2);</pre><h3>⚠️ What’s the issue here?</h3><p>All reads are <strong>synchronous</strong> — meaning they block execution until the file is read. This becomes a problem for I/O-heavy apps, slowing down performance.</p><h3>⚙️ I/O-Bound vs CPU-Bound Tasks</h3><h3>🔥 CPU-Bound</h3><p>These tasks are limited by processing power (math-heavy operations):</p><pre>let ans = 0;<br>for (let i = 1; i &lt;= 1000000; i++) {<br>	ans += i;<br>}<br>console.log(ans);</pre><p>🧠 <em>Real-world analogy</em>: Running 3 miles — you’re constantly active and engaged.</p><h3>💧 I/O-Bound</h3><p>Limited by data transfer speed (waiting for input/output):</p><pre>const fs = require(&quot;fs&quot;);</pre><pre>const contents = fs.readFileSync(&quot;a.txt&quot;, &quot;utf-8&quot;);<br>console.log(contents);</pre><p>🧠 <em>Real-world analogy</em>: Boiling water — you start it and wait.</p><h3>🧮 Functional Arguments</h3><p>Let’s write a calculator using different styles.</p><h3>Approach #1: Direct calls</h3><pre>function sum(a, b) { return a + b; }<br>function multiply(a, b) { return a * b; }<br>function subtract(a, b) { return a - b; }<br>function divide(a, b) { return a / b; }</pre><pre>console.log(sum(1, 2));</pre><h3>Approach #2: Pass the operation as a function</h3><pre>function doOperation(a, b, op) {<br>  return op(a, b);<br>}</pre><pre>console.log(doOperation(1, 2, sum)); // 3</pre><p>This shows the power of <strong>functions as first-class citizens</strong> in JavaScript.</p><h3>⏳ Asynchronous Code &amp; Callbacks</h3><p>Let’s read from a file asynchronously using a <strong>callback</strong> function:</p><pre>const fs = require(&quot;fs&quot;);</pre><pre>fs.readFile(&quot;a.txt&quot;, &quot;utf-8&quot;, function (err, contents) {<br>  console.log(contents);<br>});</pre><h3>🕒 setTimeout</h3><p>Another example of async behavior:</p><pre>function run() {<br>	console.log(&quot;I will run after 1s&quot;);<br>}</pre><pre>setTimeout(run, 1000);<br>console.log(&quot;I will run immediately&quot;);</pre><p>Even though setTimeout is called first, the last log executes first.</p><h3>🧩 Real World Analogy for Async Behavior</h3><p><strong>You have to:</strong></p><ol><li>Boil water</li><li>Do laundry</li><li>Send a package</li></ol><p>You can:</p><ul><li>Do them <strong>one by one</strong> (synchronous)</li><li><strong>Switch</strong> between tasks (concurrent)</li><li><strong>Start all</strong> and respond as each finishes (asynchronous)</li></ul><p>🎥 Good talk: <a href="https://www.youtube.com/watch?v=oV9rvDllKEg">Concurrency is not parallelism</a></p><h3>🔄 JavaScript Architecture for Asynchronous Code</h3><p>JavaScript is <strong>single-threaded</strong>, meaning it can only do one thing at a time. So how does it handle tasks like file reading, API calls, or timers <em>without freezing the entire application</em>?</p><p>That’s where JavaScript’s <strong>event-driven architecture</strong> comes into play — it uses <strong>asynchronous operations</strong>, <strong>callback queues</strong>, and an <strong>event loop</strong> to simulate multitasking.</p><p>Let’s break this down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zUhbLaDV5YjEbVvNRLYNA.png" /></figure><h3>🧠 1. Call Stack</h3><p><strong>What it is</strong>:<br> The <strong>call stack</strong> is like a stack of plates — functions are pushed onto it when called and popped off when they finish.</p><p><strong>It follows LIFO (Last In, First Out)</strong>.<br> The last function added is the first to finish.</p><p><strong>Example:</strong></p><pre>function greet() {<br>  console.log(&quot;Hello&quot;);<br>}</pre><pre>function start() {<br>  greet();        // &lt;-- greet is pushed onto the stack<br>  console.log(&quot;Started&quot;);<br>}</pre><pre>start();          // &lt;-- start is pushed first</pre><p><strong>How the stack works:</strong></p><pre>PUSH: start()<br>   └──&gt; PUSH: greet()<br>            └──&gt; console.log(&quot;Hello&quot;) → POP: greet()<br>   └──&gt; console.log(&quot;Started&quot;) → POP: start()</pre><p>Only one function can run at a time on this stack. So JS needs a way to handle <em>waiting</em> operations — that’s where Web APIs and the event loop come in.</p><h3>🌐 2. Web APIs</h3><p><strong>What they are</strong>:<br> These are <strong>background workers provided by the browser or Node.js</strong>, <em>not JavaScript itself</em>. They handle long-running operations like:</p><ul><li>setTimeout()</li><li>fetch() API</li><li>readFile() in Node.js</li><li>DOM event listeners</li></ul><p>These APIs run in parallel (outside the call stack) and notify JS when they’re done.</p><p><strong>Example:</strong></p><pre>setTimeout(() =&gt; {<br>  console.log(&quot;Hello after 2 seconds&quot;);<br>}, 2000);</pre><ul><li>The timer is set in the <strong>Web API environment</strong>.</li><li>After 2 seconds, the callback () =&gt; { console.log(...) } is moved to the <strong>callback queue</strong>.</li></ul><h3>📥 3. Callback Queue</h3><p><strong>What it is</strong>:<br> The <strong>callback queue</strong> holds functions waiting to be executed once the <strong>call stack is empty</strong>.</p><p>Think of it as a “waiting room” where finished async tasks stand in line.</p><p><strong>Visual analogy</strong>:<br> Imagine a bouncer (event loop) who checks if the dance floor (call stack) is empty. If it is, they let the next person (callback) in from the queue.</p><h3>🔁 4. Event Loop</h3><p><strong>What it does</strong>:<br> The <strong>event loop</strong> is a constant checker — it monitors the call stack and the callback queue.</p><ul><li>If the call stack is empty</li><li>And the callback queue has something</li><li>It <strong>moves the first callback from the queue to the stack</strong></li></ul><p><strong>Diagram Summary:</strong></p><pre>async task (e.g., setTimeout)<br>                  ↓<br>         [ Web APIs handle it ]<br>                  ↓<br>    once done → push callback to Queue<br>                  ↓<br>        [ Event Loop checks Stack ]<br>                  ↓<br>       if empty → push to Call Stack</pre><h3>🧪 Example That Uses It All</h3><pre>console.log(&quot;Start&quot;);</pre><pre>setTimeout(() =&gt; {<br>  console.log(&quot;After timeout&quot;);<br>}, 2000);</pre><pre>console.log(&quot;End&quot;);</pre><p><strong>Execution Order:</strong></p><ol><li>&quot;Start&quot; → printed</li><li>setTimeout → moved to Web APIs</li><li>&quot;End&quot; → printed</li><li>2 seconds later → callback goes to the queue</li><li>Call stack is empty → callback runs → &quot;After timeout&quot; printed</li></ol><h3>🔗 Visual Playground</h3><p>Want to <em>see</em> this in action? Use this:<br> 👉 <a href="http://latentflip.com/loupe/">http://latentflip.com/loupe/</a></p><p>It’s an interactive tool where you can visualize:</p><ul><li>Call stack</li><li>Web APIs</li><li>Callback queue</li><li>Event loop behavior</li></ul><h3>🏁 TL;DR — The Full Architecture:</h3><p>### 🏁 TL;DR — The Full Architecture</p><p>| **Component** | **Role** |<br>| **Call Stack** | Executes current JS code (1 thing at a time) |<br>| **Web APIs** | Handles async tasks in parallel (timers, I/O, fetch) |<br>| **Callback Queue**| Queues callbacks when async tasks complete |<br>| **Event Loop** | Moves tasks from the queue to the stack when the stack is empty |</p><h3>🧠 Final Thoughts</h3><p>Understanding how functions, synchronous vs asynchronous code, and the event loop work is critical to becoming a proficient JavaScript developer. Whether you’re optimizing performance or building scalable apps, mastering these concepts is your first step.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f577c43282b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript 101: Understanding the Basics]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">JavaScript 101: Understanding the Basics</p><p class="medium-feed-link"><a href="https://medium.com/@singhgurnoor080/javascript-101-understanding-the-basics-9a2ab6631ed6?source=rss-5947c9590744------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@singhgurnoor080/javascript-101-understanding-the-basics-9a2ab6631ed6?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a2ab6631ed6</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html-css-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Wed, 26 Mar 2025 16:02:05 GMT</pubDate>
            <atom:updated>2025-03-26T16:02:05.866Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Introduction to CSS: Styling Your Web Applications]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">CSS (Cascading Style Sheets) is a fundamental technology used to style web applications, making them visually appealing and user-friendly&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@singhgurnoor080/introduction-to-css-styling-your-web-applications-b1a5ada34620?source=rss-5947c9590744------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@singhgurnoor080/introduction-to-css-styling-your-web-applications-b1a5ada34620?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1a5ada34620</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Tue, 11 Mar 2025 23:16:29 GMT</pubDate>
            <atom:updated>2025-03-11T23:16:29.940Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Introduction to HTML: Building Your First Webpage]]></title>
            <link>https://medium.com/@singhgurnoor080/introduction-to-html-building-your-first-webpage-e1ff3affdf22?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1ff3affdf22</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html-css]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Mon, 10 Mar 2025 22:01:39 GMT</pubDate>
            <atom:updated>2025-03-10T22:01:39.657Z</atom:updated>
            <content:encoded><![CDATA[<p>HTML, or HyperText Markup Language, is the foundation of all websites. It provides the basic structure and content of web pages. While HTML itself does not include styling, it is the starting point for any web development project. In this guide, we will walk through creating a simple HTML file and understanding key HTML elements.</p><h3>Step 1: Creating a Simple HTML File</h3><p>To begin, follow these steps:</p><ol><li>Create a folder on your computer and name it website.</li><li>Inside the website folder, create a new file called index.html.</li><li>Open index.html in a text editor such as Visual Studio Code, Notepad++, or any other code editor of your choice.</li><li>Add the following basic HTML structure to the file:</li></ol><pre>&lt;html&gt;<br>    &lt;title&gt;<br>        Visual Studio Code - Code Editor<br>    &lt;/title&gt;<br>&lt;/html&gt;</pre><p>Save the file and open it in a web browser (Chrome, Firefox, Edge, etc.) to see your first HTML page.</p><h3>Step 2: Understanding HTML Tags</h3><p>HTML is made up of different elements, each defined by tags. Below are some common HTML tags you should know:</p><ul><li>&lt;div&gt; and &lt;span&gt;: Used for structuring and grouping content.</li><li>&lt;head&gt;: Contains metadata and links to stylesheets and scripts.</li><li>&lt;body&gt;: The main section of the webpage, where visible content is placed.</li><li>&lt;h1&gt;, &lt;h2&gt;, &lt;h3&gt;, &lt;h4&gt;, &lt;h5&gt;, &lt;h6&gt;: Heading tags for defining different levels of headings.</li><li>&lt;b&gt;, &lt;i&gt;, &lt;u&gt;: Bold, italic, and underlined text.</li><li>&lt;a&gt;: Anchor tag for creating hyperlinks.</li><li>&lt;img&gt;: Used to display images.</li><li>&lt;input&gt;: Allows user input.</li><li>&lt;button&gt;: Creates a clickable button.</li><li>&lt;br&gt;: Inserts a line break.</li></ul><h3>Step 3: Building a Basic HTML Page</h3><p>Now that we understand basic HTML elements, let’s build a simple webpage. Replace the contents of index.html with the following code:</p><pre>&lt;html&gt;<br>    &lt;head&gt;<br>        &lt;title&gt;Visual Studio Code - Code Editor&lt;/title&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;div&gt;<br>            &lt;span&gt;Visual Studio Code&lt;/span&gt;<br>            &lt;a href=&quot;/&quot;&gt;Docs&lt;/a&gt;<br>            &lt;a href=&quot;/&quot;&gt;Updates&lt;/a&gt;<br>            &lt;a href=&quot;/&quot;&gt;Blog&lt;/a&gt;<br>            &lt;a href=&quot;/&quot;&gt;API&lt;/a&gt;<br>            &lt;a href=&quot;/&quot;&gt;Extensions&lt;/a&gt;<br>            &lt;a href=&quot;/&quot;&gt;FAQs&lt;/a&gt;<br>            &lt;a href=&quot;/&quot;&gt;Learn&lt;/a&gt;<br>            <br>            &lt;input type=&quot;text&quot; placeholder=&quot;Search Docs&quot;&gt;<br>            &lt;button&gt;Download&lt;/button&gt;<br>        &lt;/div&gt;<br>        &lt;br/&gt;<br>        &lt;div&gt;<br>            &lt;a href=&quot;/&quot;&gt;Version 1.82&lt;/a&gt; is now available! Read about the new features and fixes from July.<br>        &lt;/div&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Explanation of the Code:</h3><ul><li>The &lt;head&gt; section contains the title of the page, which appears in the browser tab.</li><li>The &lt;body&gt; section contains the visible content of the webpage.</li><li>A &lt;div&gt; is used to group elements together.</li><li>&lt;span&gt; is used to highlight text.</li><li>&lt;a&gt; tags are used for navigation links.</li><li>An &lt;input&gt; field allows users to search within the documentation.</li><li>A &lt;button&gt; is used for downloading content.</li><li>A &lt;br&gt; tag adds line breaks for better readability.</li></ul><h3>Conclusion</h3><p>With this simple introduction, you now have the foundational knowledge to create an HTML page. As you progress, you can explore CSS for styling and JavaScript for interactivity. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1ff3affdf22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing my First Solana Program using Rust and Anchor]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Storing Your Favorites on the Blockchain with Solana and Anchor</p><p class="medium-feed-link"><a href="https://coinsbench.com/writing-my-first-solana-program-using-rust-and-anchor-cc0444e25884?source=rss-5947c9590744------2">Continue reading on CoinsBench »</a></p></div>]]></description>
            <link>https://coinsbench.com/writing-my-first-solana-program-using-rust-and-anchor-cc0444e25884?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc0444e25884</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[blockchain-technology]]></category>
            <category><![CDATA[solana-network]]></category>
            <category><![CDATA[anchor]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Mon, 03 Feb 2025 18:30:30 GMT</pubDate>
            <atom:updated>2025-02-05T17:17:16.492Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Getting Started with Rust: A Beginner’s Guide]]></title>
            <link>https://coinsbench.com/getting-started-with-rust-a-beginners-guide-cf165eb340ed?source=rss-5947c9590744------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf165eb340ed</guid>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Gurnoor Singh]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 09:55:48 GMT</pubDate>
            <atom:updated>2025-02-05T17:17:37.213Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re new to programming or looking to learn a modern, powerful language, Rust is an excellent choice. Rust has gained immense popularity in recent years, thanks to its performance, safety, and versatility. Whether you’re building web applications, game engines, or blockchain smart contracts, Rust has something to offer.</p><p>In this blog, we’ll explore what makes Rust unique, how to get started, and why it’s worth learning. We’ll also dive into a practical example of building a Solana smart contract using Rust. Let’s dive in!</p><h3>What is Rust?</h3><p>Rust is a systems programming language that focuses on <strong>speed</strong>, <strong>memory safety</strong>, and <strong>concurrency</strong>. It was created by Mozilla and first released in 2010. Rust is designed to prevent common programming errors like null pointer dereferencing and buffer overflows, making it a safer alternative to languages like C and C++.</p><p>Here are some key features of Rust:</p><ol><li><strong>Memory Safety</strong>: Rust uses a unique ownership model to manage memory, eliminating the need for a garbage collector.</li><li><strong>Performance</strong>: Rust is as fast as C and C++, making it ideal for performance-critical applications.</li><li><strong>Concurrency</strong>: Rust’s ownership model ensures thread safety, making it easier to write concurrent programs.</li><li><strong>Modern Tooling</strong>: Rust comes with a powerful package manager (Cargo) and excellent documentation.</li></ol><h3>Why Learn Rust?</h3><h3>1. High Demand in the Industry</h3><p>Rust is consistently ranked as one of the most loved programming languages in Stack Overflow’s annual developer survey. Companies like Microsoft, Google, and Amazon are adopting Rust for its safety and performance.</p><h3>2. Versatility</h3><p>Rust can be used for a wide range of applications, including:</p><ul><li>Web development (using frameworks like Rocket or Actix)</li><li>Game development (with libraries like Bevy)</li><li>Blockchain and smart contracts (e.g., Solana, Polkadot)</li><li>Embedded systems and IoT</li></ul><h3>3. Future-Proof Skills</h3><p>As systems become more complex, the need for safe and efficient programming languages will only grow. Learning Rust now will give you a competitive edge in the future.</p><h3>Getting Started with Rust</h3><h3>Step 1: Install Rust</h3><p>To start coding in Rust, you’ll need to install the Rust toolchain. The easiest way to do this is by using rustup, Rust&#39;s official installer.</p><ol><li>Open your terminal and run the following command:</li></ol><ul><li>curl --proto &#39;=https&#39; --tlsv1.2 -sSf https://sh.rustup.rs | sh</li></ul><ol><li>Follow the on-screen instructions to complete the installation.</li><li>Verify the installation by running:</li></ol><ul><li>rustc --version</li></ul><h3>Step 2: Write Your First Rust Program</h3><p>Let’s write a simple “Hello, World!” program in Rust.</p><ol><li>Create a new file called main.rs:</li></ol><ul><li>fn main() { println!(&quot;Hello, World!&quot;); }</li></ul><ol><li>Compile and run the program:</li></ol><ul><li>rustc main.rs ./main</li></ul><ol><li>You should see the output:</li></ol><ul><li>Hello, World!</li></ul><h3>Step 3: Learn the Basics</h3><p>Here are some core concepts to get you started with Rust:</p><h4>1. Variables and Mutability</h4><p>In Rust, variables are immutable by default. Use the mut keyword to make them mutable.</p><pre>let x = 5; // immutable<br>let mut y = 10; // mutable<br>y = 20; // allowed</pre><h4>2. Data Types</h4><p>Rust has two main data types: <strong>scalar</strong> (e.g., integers, floats, booleans) and <strong>compound</strong> (e.g., tuples, arrays).</p><pre>let num: i32 = 42; // integer<br>let pi: f64 = 3.14; // float<br>let is_rust_fun: bool = true; // boolean<br>let tuple: (i32, f64, bool) = (42, 3.14, true); // tuple</pre><h4>3. Functions</h4><p>Functions are defined using the fn keyword.</p><pre>fn add(a: i32, b: i32) -&gt; i32 {<br>    a + b<br>}</pre><h4>4. Ownership and Borrowing</h4><p>Rust’s ownership model ensures memory safety. Each value has a single owner, and you can borrow references to the value.</p><pre>let s1 = String::from(&quot;hello&quot;);<br>let s2 = s1; // s1 is no longer valid<br>let s3 = &amp;s2; // borrow a reference to s2</pre><h4>5. Error Handling</h4><p>Rust uses the Result and Option types for error handling.</p><pre>fn divide(a: f64, b: f64) -&gt; Result&lt;f64, String&gt; {<br>    if b == 0.0 {<br>        Err(String::from(&quot;Division by zero&quot;))<br>    } else {<br>        Ok(a / b)<br>    }<br>}</pre><h3>Building a Solana Smart Contract with Rust</h3><p>Now that you’re familiar with the basics of Rust, let’s dive into a practical example: building a Solana smart contract. This contract will allow users to save their favorite things (like a number, color, and hobbies) on the blockchain.</p><h3>Step 1: Set Up Your Environment</h3><p>To build Solana smart contracts, you’ll need the following tools:</p><ol><li><strong>Rust</strong>: Install Rust using rustup (as shown above).</li><li><strong>Solana CLI</strong>: Install the Solana command-line tools.</li></ol><ul><li>sh -c &quot;$(curl -sSfL https://release.solana.com/stable/install)&quot;</li></ul><p><strong>3. Anchor Framework</strong>: Anchor is a framework for building Solana programs.</p><ul><li>cargo install --git https://github.com/coral-xyz/anchor anchor-cli --locked</li></ul><h3>Step 2: Write the Smart Contract</h3><pre>// Include your Solana smart contract Rust code here.</pre><h3>Step 3: Deploy and Test</h3><ol><li>Build the program:</li></ol><ul><li>anchor build</li></ul><p>2. Deploy the program to Solana:</p><ul><li>anchor deploy</li></ul><p>3. Write tests using Anchor’s testing framework.</p><h3>Final Thoughts</h3><p>Rust is a powerful and modern programming language that’s worth learning, whether you’re a beginner or an experienced developer. Its focus on safety, performance, and concurrency makes it a great choice for a wide range of applications.</p><p>If you’re ready to take the plunge, start with the Rust Book and build small projects to practice. Don’t be afraid to make mistakes — Rust’s compiler is there to guide you every step of the way.</p><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf165eb340ed" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/getting-started-with-rust-a-beginners-guide-cf165eb340ed">Getting Started with Rust: A Beginner’s Guide</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>