<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bhupesh Kumar</title>
    <description>The latest articles on DEV Community by Bhupesh Kumar (@_bhupeshk_).</description>
    <link>https://dev.to/_bhupeshk_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1277945%2Fb1413c0c-e703-418a-8360-58a59f0dc9ef.jpg</url>
      <title>DEV Community: Bhupesh Kumar</title>
      <link>https://dev.to/_bhupeshk_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_bhupeshk_"/>
    <language>en</language>
    <item>
      <title>MongoDB Made Easy: A Beginner’s Guide to NoSQL</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Thu, 19 Jun 2025 03:16:51 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/mongodb-made-easy-a-beginners-guide-to-nosql-1la9</link>
      <guid>https://dev.to/_bhupeshk_/mongodb-made-easy-a-beginners-guide-to-nosql-1la9</guid>
      <description>&lt;p&gt;Welcome to the ultimate &lt;strong&gt;MongoDB and Mongoose&lt;/strong&gt; guide — built step-by-step for both &lt;strong&gt;beginners&lt;/strong&gt; and &lt;strong&gt;intermediate&lt;/strong&gt; developers looking to master database development in the Node.js ecosystem.&lt;/p&gt;

&lt;p&gt;In this hands-on series, we’ll explore everything from the &lt;strong&gt;foundations of MongoDB&lt;/strong&gt; to &lt;strong&gt;real-world application development using Mongoose&lt;/strong&gt;, including setup, schema design, validations, middleware, transactions, performance tuning, deployment, and much more.&lt;/p&gt;

&lt;p&gt;Whether you're building your first backend app or scaling a production-grade API, this guide will walk you through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Core MongoDB operations using the shell
&lt;/li&gt;
&lt;li&gt;Creating schemas and models with Mongoose
&lt;/li&gt;
&lt;li&gt;Handling relationships and validations
&lt;/li&gt;
&lt;li&gt;Writing clean, production-ready CRUD APIs
&lt;/li&gt;
&lt;li&gt;Performance optimization &amp;amp; best practices
&lt;/li&gt;
&lt;li&gt;Full backend integration with Express.js
&lt;/li&gt;
&lt;li&gt;Deployment-ready strategies and tips&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;No fluff. Just practical, code-first explanations with real examples and structured sections.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of JavaScript&lt;/li&gt;
&lt;li&gt;Node.js installed on your machine&lt;/li&gt;
&lt;li&gt;A terminal and code editor (e.g., VS Code)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt; Bookmark this guide and revisit as you scale your backend knowledge. You’ll find clear explanations, code snippets, and mini challenges throughout.&lt;/p&gt;

&lt;p&gt;Let’s dive into the world of fast, flexible, and scalable backend development with &lt;strong&gt;MongoDB + Mongoose&lt;/strong&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Installation Video
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=tC49Nzm6SyM" rel="noopener noreferrer"&gt;Youtube video (for Complete Installation help):&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The MongoDB Shell
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;MongoDB Shell&lt;/strong&gt; (&lt;code&gt;mongosh&lt;/code&gt;) is an interactive JavaScript interface to communicate with your MongoDB server. It lets you query, update, and manage your databases and collections.&lt;/p&gt;




&lt;h4&gt;
  
  
  Starting the Shell
&lt;/h4&gt;

&lt;p&gt;If MongoDB is installed locally, open your terminal and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongosh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;show dbs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;List all databases&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;use &amp;lt;dbname&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Switch to or create a database&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;db.createCollection()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Create a new collection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;db.&amp;lt;collection&amp;gt;.insertOne()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Add a document&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;db.&amp;lt;collection&amp;gt;.find()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retrieve documents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;db.&amp;lt;collection&amp;gt;.updateOne()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Modify document&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;db.&amp;lt;collection&amp;gt;.deleteOne()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Remove document&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  How MongoDB Stores Data — BSON
&lt;/h3&gt;

&lt;p&gt;MongoDB stores data in a format called &lt;strong&gt;BSON&lt;/strong&gt; (Binary JSON).&lt;/p&gt;




&lt;h4&gt;
  
  
  What is BSON?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;BSON&lt;/strong&gt; stands for &lt;strong&gt;Binary JavaScript Object Notation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;It is a &lt;strong&gt;binary-encoded&lt;/strong&gt; serialization format.&lt;/li&gt;
&lt;li&gt;BSON extends the JSON format with additional data types such as:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Binary&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Decimal128&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ObjectId&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h4&gt;
  
  
  Why BSON and not JSON?
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;JSON&lt;/th&gt;
&lt;th&gt;BSON&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Format&lt;/td&gt;
&lt;td&gt;Text-based&lt;/td&gt;
&lt;td&gt;Binary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Slower for reading/writing&lt;/td&gt;
&lt;td&gt;Faster due to binary format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Types&lt;/td&gt;
&lt;td&gt;Limited types&lt;/td&gt;
&lt;td&gt;Richer types (Date, Binary, etc.)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Size&lt;/td&gt;
&lt;td&gt;Lightweight&lt;/td&gt;
&lt;td&gt;Slightly heavier (due to metadata)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Key Point
&lt;/h4&gt;

&lt;p&gt;While you &lt;strong&gt;write and read&lt;/strong&gt; data using &lt;strong&gt;JSON-like syntax&lt;/strong&gt;, MongoDB &lt;strong&gt;stores&lt;/strong&gt; it in BSON behind the scenes to optimize for &lt;strong&gt;speed&lt;/strong&gt; and &lt;strong&gt;flexibility&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// JSON-style document
{
  name: "Bhupesh",
  age: 24,
  isAdmin: false,
  joinedAt: new Date(),
  _id: ObjectId("60ab1234567890abcdef1234")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;When stored, this is automatically converted to BSON by MongoDB.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Documents and Collections in MongoDB
&lt;/h3&gt;

&lt;p&gt;MongoDB is a &lt;strong&gt;NoSQL database&lt;/strong&gt; that stores data in a flexible, JSON-like format.&lt;/p&gt;




&lt;h4&gt;
  
  
  What is a Document?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;Document&lt;/strong&gt; is the &lt;strong&gt;basic unit of data&lt;/strong&gt; in MongoDB.&lt;/li&gt;
&lt;li&gt;It's similar to a &lt;strong&gt;row&lt;/strong&gt; in relational databases.&lt;/li&gt;
&lt;li&gt;It is written in &lt;strong&gt;JSON-like syntax&lt;/strong&gt; but stored as &lt;strong&gt;BSON&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Documents can have nested structures (arrays, objects).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  _id: ObjectId("64f9d0b45ef65d..."),
  name: "Bhupesh",
  age: 24,
  skills: ["JavaScript", "Node.js", "MongoDB"],
  isAdmin: false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What is a Collection?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A Collection is a group of documents.&lt;/li&gt;
&lt;li&gt;It is similar to a table in relational databases.&lt;/li&gt;
&lt;li&gt;Documents in a collection don’t need to have the same structure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Users Collection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ name: "Bhupesh", age: 24 }
{ name: "Alice", age: 30, city: "Toronto" }
{ name: "Dev", skills: ["Python", "SQL"] }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Key difference from SQL
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;MongoDB (NoSQL)&lt;/th&gt;
&lt;th&gt;SQL (Relational DB)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Document&lt;/td&gt;
&lt;td&gt;Row&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Collection&lt;/td&gt;
&lt;td&gt;Table&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Field (key)&lt;/td&gt;
&lt;td&gt;Column&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BSON format&lt;/td&gt;
&lt;td&gt;Tabular format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema-less&lt;/td&gt;
&lt;td&gt;Fixed schema&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Conclusion:
&lt;/h4&gt;

&lt;p&gt;MongoDB’s flexibility allows each document in a collection to store different fields and structures, making it ideal for modern applications with evolving data needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Insert in MongoDB using &lt;code&gt;insertOne()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;insertOne()&lt;/code&gt; method is used to &lt;strong&gt;insert a single document&lt;/strong&gt; into a MongoDB collection.&lt;/p&gt;




&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.insertOne(document)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example (Mongo Shell):
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.insertOne({
  name: "Bhupesh",
  age: 25,
  email: "bhupesh@example.com",
  isAdmin: true
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This will insert one document into the users collection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Example using Node.js with MongoDB Driver:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { MongoClient } = require("mongodb");

async function run() {
  const uri = "mongodb://localhost:27017";
  const client = new MongoClient(uri);

  try {
    await client.connect();
    const db = client.db("myAppDB");
    const users = db.collection("users");

    const result = await users.insertOne({
      name: "Alice",
      age: 30,
      city: "Toronto"
    });

    console.log("Inserted ID:", result.insertedId);
  } finally {
    await client.close();
  }
}

run().catch(console.error);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Notes:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Automatically creates the collection if it doesn’t exist.&lt;/li&gt;
&lt;li&gt;Adds a unique _id field if not specified.&lt;/li&gt;
&lt;li&gt;Returns an object containing insertedId and acknowledged: true&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Insert Multiple Documents using &lt;code&gt;insertMany()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;insertMany()&lt;/code&gt; method is used to &lt;strong&gt;insert multiple documents&lt;/strong&gt; into a MongoDB collection in one go.&lt;/p&gt;




&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.insertMany([document1, document2, ...])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example (Mongo Shell):
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.insertMany([
  { name: "Bhupesh", age: 25 },
  { name: "Alice", age: 30 },
  { name: "John", age: 22 }
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This will insert all the objects into the users collection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Find Documents in MongoDB
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;find()&lt;/code&gt; method is used to &lt;strong&gt;retrieve documents&lt;/strong&gt; from a MongoDB collection. You can query all documents or filter using criteria.&lt;/p&gt;




&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection.find(query, projection)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example 1: Find All Documents
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.find()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns all documents from the users collection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Example 2: Find with Condition
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.find({ age: { $gt: 25 } }) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns users whose age is greater than 25.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Example 3: Find Specific Fields Only
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.find({ age: { $gt: 25 } }, { name: 1, _id: 0 })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns only the name field (excluding _id).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Example 4: Find One Document
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.findOne({ name: "Bhupesh" })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns the first matching document.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  MongoDB Query Operators
&lt;/h3&gt;

&lt;p&gt;Query operators in MongoDB are used to &lt;strong&gt;filter documents&lt;/strong&gt; based on specific conditions.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Comparison Operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$eq&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equals&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ age: { $eq: 25 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$ne&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ status: { $ne: "inactive" }}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$gt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ age: { $gt: 30 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$lt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ age: { $lt: 50 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$gte&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ score: { $gte: 90 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$lte&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ score: { $lte: 60 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Logical Operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$and&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches documents that satisfy all clauses&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ $and: [ { age: { $gt: 18 } }, { age: { $lt: 60 } } ] }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$or&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches documents that satisfy any clause&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ $or: [ { age: 20 }, { name: "Bhupesh" } ] }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$not&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Inverts the effect of a query expression&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ age: { $not: { $gt: 18 } } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$nor&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches none of the expressions&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ $nor: [ { status: "inactive" }, { age: { $lt: 18 } } ] }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Element Operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$exists&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if the field exists&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ email: { $exists: true } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$type&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks the BSON type of a field&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ age: { $type: "int" } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;Array Operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$in&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches any value in the array&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ age: { $in: [20, 25, 30] } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$nin&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches none of the values in the array&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ status: { $nin: ["inactive", "banned"] } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$all&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches arrays that contain all specified elements&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ tags: { $all: ["node", "js"] } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$size&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches arrays with a specific number of elements&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ tags: { $size: 3 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$elemMatch&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Matches documents that contain an array element that matches all criteria&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ scores: { $elemMatch: { $gt: 80, $lt: 100 } } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Example Usage
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.find({
  $and: [
    { age: { $gt: 18 } },
    { status: { $ne: "inactive" } }
  ]
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  UPDATE in MongoDB
&lt;/h3&gt;

&lt;p&gt;MongoDB provides methods to update documents in a collection.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;code&gt;updateOne()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Updates &lt;strong&gt;a single document&lt;/strong&gt; that matches the filter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.updateOne(
  { name: "Bhupesh" },
  { $set: { age: 26 } }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This will update the age field of the first document where name is "Bhupesh"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  updateMany()
&lt;/h4&gt;

&lt;p&gt;Updates all documents that match the filter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.updateMany(
  { country: "Canada" },
  { $set: { isActive: true } }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This will update all users from Canada by adding or updating the isActive field.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$set&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sets the value of a field&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ $set: { age: 30 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$inc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Increments a field by a value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ $inc: { points: 10 } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$unset&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes a field from a document&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ $unset: { tempField: "" } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$rename&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Renames a field&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ $rename: { oldName: "newName" } }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Nesting in MongoDB
&lt;/h3&gt;

&lt;p&gt;MongoDB supports &lt;strong&gt;nested documents&lt;/strong&gt; (also called &lt;strong&gt;embedded documents&lt;/strong&gt;)—documents inside documents. This helps represent complex relationships directly within the document itself.&lt;/p&gt;




&lt;h4&gt;
  
  
  Example: Nested Document
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = {
  name: "Bhupesh",
  age: 25,
  address: {
    street: "123 King St",
    city: "Toronto",
    country: "Canada"
  }
};

db.users.insertOne(user);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Here, address is a nested object inside the user document.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Accessing Nested Fields
&lt;/h4&gt;

&lt;p&gt;Use dot notation to query or update nested fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Find users in Toronto
db.users.find({ "address.city": "Toronto" });

// Update the country of a nested address
db.users.updateOne(
  { name: "Bhupesh" },
  { $set: { "address.country": "USA" } }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Nesting Arrays of Documents
&lt;/h4&gt;

&lt;p&gt;MongoDB also allows arrays of nested documents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const blog = {
  title: "My Blog Post",
  comments: [
    { user: "Alice", text: "Great post!" },
    { user: "Bob", text: "Thanks for sharing." }
  ]
};

db.blogs.insertOne(blog);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Querying Nested Arrays
&lt;/h4&gt;

&lt;p&gt;You can also query nested arrays of documents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.blogs.find({ "comments.user": "Alice" });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nesting in MongoDB helps reduce the need for joins and keeps related data together. Use it wisely for better performance and data organization!&lt;/p&gt;

&lt;h3&gt;
  
  
  DELETE in MongoDB
&lt;/h3&gt;

&lt;p&gt;In MongoDB, you can delete documents from a collection using two main methods:&lt;/p&gt;




&lt;h4&gt;
  
  
  deleteOne()
&lt;/h4&gt;

&lt;p&gt;Deletes the &lt;strong&gt;first&lt;/strong&gt; document that matches the query criteria.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.deleteOne({ name: "Bhupesh" });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If multiple documents match, only the first one will be deleted.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  deleteMany()
&lt;/h4&gt;

&lt;p&gt;Deletes all documents that match the query criteria.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.deleteMany({ age: { $lt: 18 } });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Deletes all users under the age of 18.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Delete All Documents (Use Carefully)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.deleteMany({});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This will remove all documents from the users collection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Deleting by _id
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.users.deleteOne({ _id: ObjectId("60f6f6f6f6f6f6f6f6f6f6f6") });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You must use ObjectId() when deleting by _id.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;MongoDB also supports soft deletes (e.g., marking as deleted with a flag), but you must implement this manually using a field like isDeleted: true.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Mongoose?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mongoose&lt;/strong&gt; is an &lt;strong&gt;Object Data Modeling (ODM)&lt;/strong&gt; library for &lt;strong&gt;MongoDB&lt;/strong&gt; and &lt;strong&gt;Node.js&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It provides a &lt;strong&gt;straightforward, schema-based solution&lt;/strong&gt; to model your application data.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Use Mongoose?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Simplifies interaction with MongoDB using models.&lt;/li&gt;
&lt;li&gt;Allows you to define &lt;strong&gt;schemas&lt;/strong&gt; with field types and validations.&lt;/li&gt;
&lt;li&gt;Provides &lt;strong&gt;middleware hooks&lt;/strong&gt; and &lt;strong&gt;custom methods&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Supports &lt;strong&gt;relationships&lt;/strong&gt; using population.&lt;/li&gt;
&lt;li&gt;Handles complex &lt;strong&gt;querying and data manipulation&lt;/strong&gt; easily.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Installation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install mongoose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Basic Setup Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');

// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/myApp')
  .then(() =&amp;gt; console.log('Connected to MongoDB'))
  .catch(err =&amp;gt; console.log(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Define a Schema and Model
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userSchema = new mongoose.Schema({
  name: String,
  email: String,
  age: Number
});

const User = mongoose.model('User', userSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create and Save a Document
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = new User({
  name: "Bhupesh",
  email: "bhupesh@example.com",
  age: 25
});

user.save()
  .then(doc =&amp;gt; console.log("Saved:", doc))
  .catch(err =&amp;gt; console.log(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Common Operations
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;User.find()&lt;/li&gt;
&lt;li&gt;User.findById()&lt;/li&gt;
&lt;li&gt;User.findOne()&lt;/li&gt;
&lt;li&gt;User.updateOne()&lt;/li&gt;
&lt;li&gt;User.deleteOne()&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installation and Setup of Mongoose
&lt;/h3&gt;

&lt;p&gt;Mongoose helps Node.js apps connect and interact with MongoDB in a structured and efficient way.&lt;/p&gt;




&lt;h4&gt;
  
  
  Step 1: Install Mongoose
&lt;/h4&gt;

&lt;p&gt;Use &lt;strong&gt;npm&lt;/strong&gt; to install Mongoose in your Node.js project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install mongoose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Create Project Files
&lt;/h4&gt;

&lt;p&gt;Your folder structure might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myApp/
├── node_modules/
├── index.js
├── package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Connect to MongoDB
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js
const mongoose = require('mongoose');

// Connect to local MongoDB
mongoose.connect("mongodb://127.0.0.1:27017/myDatabase")
  .then(() =&amp;gt; console.log("✅ Connected to MongoDB"))
  .catch((err) =&amp;gt; console.error("❌ Connection error", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Replace myDatabase with your actual database name.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Mongoose Schema
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Mongoose Schema&lt;/strong&gt; defines the structure of the documents within a MongoDB collection. It specifies the &lt;strong&gt;fields&lt;/strong&gt;, &lt;strong&gt;data types&lt;/strong&gt;, &lt;strong&gt;validations&lt;/strong&gt;, and even &lt;strong&gt;default values&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Create a Basic Schema
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require("mongoose");

const userSchema = new mongoose.Schema({
  name: String,
  email: String,
  age: Number
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add Validations and Options
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,       // Mandatory field
    trim: true            // Removes whitespace
  },
  email: {
    type: String,
    required: true,
    unique: true,         // No duplicate emails
    lowercase: true       // Automatically converts to lowercase
  },
  age: {
    type: Number,
    min: 0,               // Minimum age validation
    default: 18           // Default value
  },
  createdAt: {
    type: Date,
    default: Date.now
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Convert Schema to Model
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const User = mongoose.model("User", userSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Now, User can be used to create, read, update, and delete users in the users collection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Notes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A schema is just a blueprint; it needs to be compiled into a model.&lt;/li&gt;
&lt;li&gt;Once compiled, the model gives you access to powerful Mongoose methods like find(), save(), deleteOne(), etc.&lt;/li&gt;
&lt;li&gt;You can also define custom methods, virtuals, and middleware on schemas.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Mongoose Models
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Model&lt;/strong&gt; is a wrapper for a Mongoose schema. It provides an interface to interact with documents in a MongoDB collection.&lt;/p&gt;




&lt;h4&gt;
  
  
  How to Create a Model
&lt;/h4&gt;

&lt;p&gt;After defining a schema, use &lt;code&gt;mongoose.model()&lt;/code&gt; to create a model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');

// Define Schema
const userSchema = new mongoose.Schema({
  name: String,
  email: String,
  age: Number
});

// Create Model
const User = mongoose.model("User", userSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;"User" is the name of the model.&lt;/li&gt;
&lt;li&gt;Mongoose will create a collection called users (lowercased and pluralized).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task&lt;/th&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Create&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;new User()&lt;/code&gt; + &lt;code&gt;.save()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Read&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;find()&lt;/code&gt;, &lt;code&gt;findOne()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Update&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;updateOne()&lt;/code&gt;, &lt;code&gt;findByIdAndUpdate()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delete&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;deleteOne()&lt;/code&gt;, &lt;code&gt;findByIdAndDelete()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Insert in Mongoose
&lt;/h3&gt;

&lt;p&gt;Inserting data into MongoDB using Mongoose is simple and efficient using the &lt;strong&gt;Model instance&lt;/strong&gt; or &lt;strong&gt;Model.create()&lt;/strong&gt; method.&lt;/p&gt;




&lt;h4&gt;
  
  
  Method 1: Using &lt;code&gt;new Model()&lt;/code&gt; and &lt;code&gt;.save()&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');

// Define schema
const userSchema = new mongoose.Schema({
  name: String,
  email: String,
  age: Number
});

// Create model
const User = mongoose.model("User", userSchema);

// Create a new user
const newUser = new User({
  name: "Bhupesh",
  email: "bhupesh@example.com",
  age: 25
});

// Save the user to the database
newUser.save()
  .then(result =&amp;gt; console.log("✅ Saved:", result))
  .catch(err =&amp;gt; console.log("❌ Error:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Method 2: Using Model.create()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.create({
  name: "Alice",
  email: "alice@example.com",
  age: 30
})
.then(result =&amp;gt; console.log("✅ User created:", result))
.catch(err =&amp;gt; console.log("❌ Error creating user:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Method 3: Insert Many Documents at Once
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.insertMany([
  { name: "John", email: "john@example.com", age: 28 },
  { name: "Jane", email: "jane@example.com", age: 22 }
])
.then(result =&amp;gt; console.log("✅ Users inserted:", result))
.catch(err =&amp;gt; console.log("❌ Insertion error:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Tips
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use .save() when you need to manipulate or validate the instance before saving.&lt;/li&gt;
&lt;li&gt;Use .create() or .insertMany() for quicker, cleaner inserts.&lt;/li&gt;
&lt;li&gt;Mongoose handles schema validations automatically before insertion.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Operation Buffering in Mongoose
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Operation Buffering&lt;/strong&gt; in Mongoose allows you to run database operations &lt;strong&gt;before&lt;/strong&gt; a successful connection is established to MongoDB.&lt;/p&gt;




&lt;h4&gt;
  
  
  What Does That Mean?
&lt;/h4&gt;

&lt;p&gt;You can perform operations (like &lt;code&gt;.save()&lt;/code&gt; or &lt;code&gt;.find()&lt;/code&gt;) immediately after defining your model—even &lt;strong&gt;before&lt;/strong&gt; the connection to the database is fully established. Mongoose queues those operations and &lt;strong&gt;executes them once the connection is ready&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({ name: String });
const User = mongoose.model("User", userSchema);

// Save user before connecting
const newUser = new User({ name: "Bhupesh" });
newUser.save().then(() =&amp;gt; console.log("✅ Saved even before connection!"));

// Connect afterward
mongoose.connect("mongodb://127.0.0.1:27017/demoDB")
  .then(() =&amp;gt; console.log("📡 Connected to MongoDB"))
  .catch(err =&amp;gt; console.error("❌ Connection error:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Why It’s Useful
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Makes development smoother.&lt;/li&gt;
&lt;li&gt;Prevents crashes from unintentional timing issues.&lt;/li&gt;
&lt;li&gt;Helps with serverless platforms or apps with delayed DB readiness.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  When to Avoid
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In production apps where you want full control over database timing.&lt;/li&gt;
&lt;li&gt;When you're handling connections manually.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Find in Mongoose
&lt;/h3&gt;

&lt;p&gt;Mongoose provides several methods to &lt;strong&gt;retrieve documents&lt;/strong&gt; from a MongoDB collection. The most commonly used methods are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;find()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;findOne()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;findById()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  1. &lt;code&gt;find()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Returns &lt;strong&gt;all documents&lt;/strong&gt; that match the query as an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find({ age: { $gte: 18 } })
  .then(users =&amp;gt; console.log(users))
  .catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. findOne()
&lt;/h4&gt;

&lt;p&gt;Returns the first document that matches the query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.findOne({ name: "Bhupesh" })
  .then(user =&amp;gt; console.log(user))
  .catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns the first user with the name "Bhupesh".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  3. findById()
&lt;/h4&gt;

&lt;p&gt;Used to find a document using its _id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.findById("66507e7a342823aa9f34b215")
  .then(user =&amp;gt; console.log(user))
  .catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Make sure to pass a valid ObjectId as a string.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Tip: Use Projections
&lt;/h4&gt;

&lt;p&gt;You can specify which fields to return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find({}, "name email")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Only returns the name and email fields for all users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Tip: Use Filters and Sorts
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find({ age: { $gt: 18 } })
  .sort({ name: 1 })   // ascending
  .limit(5)            // limit results
  .skip(10);           // skip first 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Update in Mongoose
&lt;/h3&gt;

&lt;p&gt;Mongoose provides several methods to &lt;strong&gt;update documents&lt;/strong&gt; in a MongoDB collection.&lt;/p&gt;




&lt;h4&gt;
  
  
  Common Update Methods
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;updateOne()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Updates the &lt;strong&gt;first&lt;/strong&gt; matched document&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;updateMany()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Updates &lt;strong&gt;all&lt;/strong&gt; matched documents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;findByIdAndUpdate()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds a document by &lt;code&gt;_id&lt;/code&gt; and updates it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;findOneAndUpdate()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Finds one doc matching query &amp;amp; updates&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  updateOne()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.updateOne(
  { name: "Bhupesh" },
  { $set: { age: 26 } }
)
.then(res =&amp;gt; console.log("Updated:", res))
.catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  updateMany()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.updateMany(
  { age: { $lt: 18 } },
  { $set: { minor: true } }
)
.then(res =&amp;gt; console.log("Updated:", res))
.catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  findByIdAndUpdate()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.findByIdAndUpdate(
  "66507e7a342823aa9f34b215",
  { age: 30 },
  { new: true } // returns updated document
)
.then(user =&amp;gt; console.log("Updated User:", user))
.catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  findOneAndUpdate()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.findOneAndUpdate(
  { email: "bhupesh@example.com" },
  { $inc: { age: 1 } },
  { new: true }
)
.then(user =&amp;gt; console.log("Updated:", user));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Update Options
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;new: true&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns updated doc instead of old version&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;upsert&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Creates new doc if no match found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;runValidators: true&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Enforces schema validations during update&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Tip
&lt;/h4&gt;

&lt;p&gt;Always use $set when updating fields to avoid replacing the entire document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ $set: { name: "Alice" } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Delete in Mongoose
&lt;/h3&gt;

&lt;p&gt;Mongoose provides multiple methods to &lt;strong&gt;remove documents&lt;/strong&gt; from a MongoDB collection:&lt;/p&gt;




&lt;h4&gt;
  
  
  deleteOne()
&lt;/h4&gt;

&lt;p&gt;Deletes the &lt;strong&gt;first document&lt;/strong&gt; that matches the query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.deleteOne({ name: "Bhupesh" })
  .then(result =&amp;gt; console.log("✅ Deleted:", result))
  .catch(err =&amp;gt; console.error("❌ Error:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  deleteMany()
&lt;/h4&gt;

&lt;p&gt;Deletes all documents that match the query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.deleteMany({ age: { $lt: 18 } })
  .then(result =&amp;gt; console.log("✅ Deleted minors:", result))
  .catch(err =&amp;gt; console.error("❌ Error:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  findByIdAndDelete()
&lt;/h4&gt;

&lt;p&gt;Finds a document by _id and deletes it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.findByIdAndDelete("66507e7a342823aa9f34b215")
  .then(deletedUser =&amp;gt; console.log("✅ Deleted User:", deletedUser))
  .catch(err =&amp;gt; console.error("❌ Error:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  findOneAndDelete()
&lt;/h4&gt;

&lt;p&gt;Deletes the first matching document and returns it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.findOneAndDelete({ email: "test@example.com" })
  .then(deleted =&amp;gt; console.log("✅ Deleted:", deleted))
  .catch(err =&amp;gt; console.error("❌ Error:", err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Notes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;All methods return a promise.&lt;/li&gt;
&lt;li&gt;findOneAndDelete() and findByIdAndDelete() return the deleted document.&lt;/li&gt;
&lt;li&gt;deleteOne() and deleteMany() return a result object with deletedCount.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Schema Validations in Mongoose
&lt;/h3&gt;

&lt;p&gt;Mongoose allows you to enforce &lt;strong&gt;data integrity&lt;/strong&gt; through schema-based validations. This ensures that your documents meet certain criteria &lt;strong&gt;before being saved&lt;/strong&gt; to the database.&lt;/p&gt;




&lt;h4&gt;
  
  
  Example Schema with Validations
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,         // Must be provided
    minlength: 3,           // At least 3 characters
    maxlength: 50           // Max 50 characters
  },
  email: {
    type: String,
    required: true,
    unique: true,           // No duplicates allowed
    match: /.+\@.+\..+/     // Must match email pattern
  },
  age: {
    type: Number,
    min: 18,                // Minimum age
    max: 100                // Maximum age
  },
  isAdmin: {
    type: Boolean,
    default: false
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Common Validation Options
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;required&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Field must be present&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;min&lt;/code&gt; / &lt;code&gt;max&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;For numbers: min and max values&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;minlength&lt;/code&gt; / &lt;code&gt;maxlength&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;For strings: length limits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Must match a regex (e.g., email)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;enum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Must be one of a set of allowed values&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;default&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Value to use if none is provided&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;unique&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Enforces uniqueness in MongoDB (index)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Custom Validation Function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const productSchema = new mongoose.Schema({
  price: {
    type: Number,
    validate: {
      validator: (val) =&amp;gt; val &amp;gt; 0,
      message: 'Price must be greater than zero!'
    }
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Notes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Validations run on .save() and .create() by default.&lt;/li&gt;
&lt;li&gt;Use { runValidators: true } when updating documents.&lt;/li&gt;
&lt;li&gt;Unique is a MongoDB index, not a validation. Handle duplication errors manually if needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Mongoose SchemaType Options
&lt;/h3&gt;

&lt;p&gt;Mongoose provides a set of &lt;strong&gt;SchemaType options&lt;/strong&gt; that define how data is stored, validated, and handled inside MongoDB collections.&lt;/p&gt;

&lt;p&gt;These options can be applied to individual fields in a schema.&lt;/p&gt;




&lt;h4&gt;
  
  
  Common SchemaType Options
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;type&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Defines the data type (String, Number, Date, etc.)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;required&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Makes the field mandatory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;default&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sets a default value if none is provided&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;unique&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Creates a unique index (Note: not a validation)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;enum&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Restricts values to a fixed set (like categories or status)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;min&lt;/code&gt; / &lt;code&gt;max&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;For numbers (min and max values); For dates (earliest/latest)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;minlength&lt;/code&gt; / &lt;code&gt;maxlength&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;For strings (length restrictions)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Validates string against a regular expression&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;validate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Provides a custom validator function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;select&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Include or exclude field from query results (e.g. &lt;code&gt;select: false&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;immutable&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Once set, the value cannot be changed after document creation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;get&lt;/code&gt; / &lt;code&gt;set&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Custom getter/setter functions for transforming data&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Validations During Update &amp;amp; Error Handling in Mongoose
&lt;/h3&gt;

&lt;p&gt;By default, &lt;strong&gt;Mongoose does NOT run schema validations during &lt;code&gt;updateOne()&lt;/code&gt;, &lt;code&gt;updateMany()&lt;/code&gt;, or &lt;code&gt;findByIdAndUpdate()&lt;/code&gt;&lt;/strong&gt; unless explicitly told to do so.&lt;/p&gt;




&lt;h4&gt;
  
  
  Enabling Validations on Update
&lt;/h4&gt;

&lt;p&gt;Use the &lt;code&gt;{ runValidators: true }&lt;/code&gt; option to enforce schema rules when updating.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.findByIdAndUpdate(
  "66507e7a342823aa9f34b215",
  { age: 15 }, // Fails if age &amp;lt; 18 (based on schema)
  { runValidators: true, new: true }
)
.then(updatedUser =&amp;gt; console.log(updatedUser))
.catch(err =&amp;gt; console.error("❌ Validation Error:", err.message));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Why It Matters?
&lt;/h4&gt;

&lt;p&gt;Without runValidators, this update would bypass validation rules like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;min, max&lt;/li&gt;
&lt;li&gt;enum, match&lt;/li&gt;
&lt;li&gt;Custom validators&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Mongoose Middleware (Hooks)
&lt;/h3&gt;

&lt;p&gt;Mongoose Middleware, also known as &lt;strong&gt;hooks&lt;/strong&gt;, allow you to run custom logic &lt;strong&gt;before or after&lt;/strong&gt; certain operations like save, remove, update, or validate.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use Middleware?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Data validation or formatting&lt;/li&gt;
&lt;li&gt;Timestamps&lt;/li&gt;
&lt;li&gt;Cascading deletes&lt;/li&gt;
&lt;li&gt;Sending emails or notifications&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Types of Middleware
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Triggered On&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pre&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Before the operation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;post&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;After the operation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Middleware Applies To:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;save&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;validate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;remove&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;updateOne&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;deleteOne&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;find&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;findOne&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;findOneAndUpdate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;findOneAndDelete&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Example: Pre-save Hook
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.pre("save", function (next) {
  console.log("📦 Before saving:", this.name);
  // modify data if needed
  this.name = this.name.trim();
  next();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Post-save Hook
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.post("save", function (doc, next) {
  console.log("✅ User saved:", doc.name);
  next();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Pre-find Hook
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.pre("find", function () {
  console.log("🔍 Running find query...");
  this.select("-password"); // exclude password from results
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Pre-remove Hook
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.pre("remove", function (next) {
  console.log(`⚠️ User ${this.name} is being removed`);
  next();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Real-World Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Hashing passwords before save&lt;/li&gt;
&lt;li&gt;Soft deletes (marking deleted instead of removing)&lt;/li&gt;
&lt;li&gt;Creating audit logs&lt;/li&gt;
&lt;li&gt;Formatting timestamps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mongoose Middleware is a powerful way to plug in logic around lifecycle events of your documents.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mongoose Instance Methods &amp;amp; Static Methods
&lt;/h3&gt;

&lt;p&gt;Mongoose allows you to add &lt;strong&gt;custom methods&lt;/strong&gt; to your models in two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Instance Methods&lt;/strong&gt;: Run on individual documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static Methods&lt;/strong&gt;: Run on the Model (i.e., the entire collection).&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Instance Methods
&lt;/h4&gt;

&lt;p&gt;These methods are defined on the &lt;strong&gt;document instance&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userSchema = new mongoose.Schema({
  name: String,
  email: String
});

userSchema.methods.sayHello = function () {
  return `Hi, I’m ${this.name}`;
};

const User = mongoose.model("User", userSchema);

const user = new User({ name: "Bhupesh", email: "bhupesh@example.com" });
console.log(user.sayHello());  // Output: Hi, I’m Bhupesh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Formatting user data&lt;/li&gt;
&lt;li&gt;Checking user roles or permissions&lt;/li&gt;
&lt;li&gt;Document-specific logic&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Static Methods
&lt;/h4&gt;

&lt;p&gt;These methods are attached to the Model class, not the document.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.statics.findByEmail = function (email) {
  return this.findOne({ email });
};

const User = mongoose.model("User", userSchema);

User.findByEmail("bhupesh@example.com")
  .then(user =&amp;gt; console.log(user))
  .catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Custom queries on the collection&lt;/li&gt;
&lt;li&gt;Aggregation helpers&lt;/li&gt;
&lt;li&gt;Global filters (e.g., find all active users)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Note
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use regular functions (not arrow functions) to access this.&lt;/li&gt;
&lt;li&gt;this in instance methods → refers to the document.&lt;/li&gt;
&lt;li&gt;this in static methods → refers to the model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Model methods help organize and encapsulate business logic close to your data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mongoose Relationships (&lt;code&gt;ref&lt;/code&gt; &amp;amp; &lt;code&gt;.populate()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;In MongoDB (and Mongoose), &lt;strong&gt;relationships&lt;/strong&gt; between documents are created using the &lt;code&gt;ref&lt;/code&gt; option. This allows documents to reference other documents—similar to a foreign key in SQL.&lt;/p&gt;




&lt;h4&gt;
  
  
  Defining Relationships with &lt;code&gt;ref&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Let’s say we have two models: &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Post&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: One-to-Many (User → Posts)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// models/User.js
const mongoose = require("mongoose");

const userSchema = new mongoose.Schema({
  name: String,
  email: String
});

module.exports = mongoose.model("User", userSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// models/Post.js
const mongoose = require("mongoose");

const postSchema = new mongoose.Schema({
  title: String,
  content: String,
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User"   // 👈 references the User model
  }
});

module.exports = mongoose.model("Post", postSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using .populate()
&lt;/h4&gt;

&lt;p&gt;The .populate() method replaces the referenced ObjectId with the actual document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Post.find()
  .populate("user")  // replaces `user` ObjectId with full user object
  .then(posts =&amp;gt; {
    console.log(posts[0].user.name);  // Access user's name
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Populate Specific Fields
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Post.find()
  .populate("user", "name email -_id")  // include name &amp;amp; email, exclude _id
  .then(console.log);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: One-to-One
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const profileSchema = new mongoose.Schema({
  bio: String,
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User"
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Many-to-Many
&lt;/h4&gt;

&lt;p&gt;You can also have an array of references:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const courseSchema = new mongoose.Schema({
  name: String,
  students: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: "User"
  }]
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Notes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Always use .populate() on the query, not on the schema.&lt;/li&gt;
&lt;li&gt;You can chain multiple .populate() calls for deeply nested population.&lt;/li&gt;
&lt;li&gt;Relationships are manual in MongoDB—no cascading updates or deletes by default.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mongoose ref and .populate() give you powerful control over document linking without losing MongoDB’s flexibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  Indexes in Mongoose
&lt;/h3&gt;

&lt;p&gt;Indexes in MongoDB improve the performance of &lt;strong&gt;read operations&lt;/strong&gt; by allowing the database to locate data faster.&lt;/p&gt;

&lt;p&gt;Mongoose lets you define indexes directly in your schema.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use Indexes?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Improve query speed&lt;/li&gt;
&lt;li&gt;Support uniqueness constraints&lt;/li&gt;
&lt;li&gt;Optimize sorting, filtering, and pagination&lt;/li&gt;
&lt;li&gt;Enable geospatial or text search&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Defining Indexes in a Schema
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userSchema = new mongoose.Schema({
  name: {
    type: String,
    index: true // simple index
  },
  email: {
    type: String,
    unique: true // creates a unique index
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Compound Index
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.index({ name: 1, email: -1 }); // ascending + descending
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Checking Indexes in MongoDB
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.collection.getIndexes({ full: true }).then(console.log);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Creating Indexes Manually
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.index({ age: 1 });
User.createIndexes(); // triggers index creation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Notes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Index creation is asynchronous.&lt;/li&gt;
&lt;li&gt;Indexes can slow down write operations, so use them wisely.&lt;/li&gt;
&lt;li&gt;MongoDB automatically creates an _id index for every document.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Dropping Indexes (if needed)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.collection.dropIndex("name_1");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Indexes are essential for scaling MongoDB apps and keeping queries fast.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mongoose Virtuals
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Virtuals&lt;/strong&gt; are properties that &lt;strong&gt;don’t get persisted&lt;/strong&gt; in MongoDB but are &lt;strong&gt;computed dynamically&lt;/strong&gt; when you access them.&lt;/p&gt;

&lt;p&gt;They're useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Derived values (e.g., full name from first + last name)&lt;/li&gt;
&lt;li&gt;Relationships (for population)&lt;/li&gt;
&lt;li&gt;Formatting data&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Defining a Virtual
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userSchema = new mongoose.Schema({
  firstName: String,
  lastName: String
});

userSchema.virtual("fullName").get(function () {
  return `${this.firstName} ${this.lastName}`;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = new User({ firstName: "Bhupesh", lastName: "Kumar" });
console.log(user.fullName);  // "Bhupesh Kumar"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting a Virtual (with Setter)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;userSchema.virtual("info").set(function (v) {
  const parts = v.split(" ");
  this.firstName = parts[0];
  this.lastName = parts[1];
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Usage:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const u = new User();
u.info = "John Doe";
console.log(u.firstName); // "John"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Virtuals in JSON
&lt;/h4&gt;

&lt;p&gt;By default, virtuals don’t appear in .toJSON() or .toObject(). To include them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const schema = new mongoose.Schema({ ... }, {
  toJSON: { virtuals: true },
  toObject: { virtuals: true }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Virtuals ≠ MongoDB Fields
&lt;/h4&gt;

&lt;p&gt;Virtuals are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not stored in the DB&lt;/li&gt;
&lt;li&gt;Only computed in JS code&lt;/li&gt;
&lt;li&gt;Useful for display, derived data, or linking logic&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Real-Life Uses
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Full names, initials&lt;/li&gt;
&lt;li&gt;isAdult from age&lt;/li&gt;
&lt;li&gt;Slugs (/posts/my-awesome-title)&lt;/li&gt;
&lt;li&gt;Counting embedded items&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Virtuals help keep your DB lean while your app logic stays rich and expressive.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aggregation Framework in Mongoose
&lt;/h3&gt;

&lt;p&gt;Aggregation is a powerful way to &lt;strong&gt;transform and analyze data&lt;/strong&gt; in MongoDB. It's used to group, filter, sort, project, and compute complex results.&lt;/p&gt;

&lt;p&gt;Mongoose provides a &lt;code&gt;.aggregate()&lt;/code&gt; method to use MongoDB’s aggregation pipeline.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model.aggregate([
  { $match: { age: { $gte: 18 } } },
  { $group: { _id: "$country", total: { $sum: 1 } } },
  { $sort: { total: -1 } }
]).then(result =&amp;gt; console.log(result));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Filters documents (like WHERE)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$group&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Groups data by a field&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$project&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Includes/excludes fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$sort&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sorts documents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$limit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Limits result count&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$skip&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Skips n documents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$count&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Counts number of documents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;$sum&lt;/code&gt;, &lt;code&gt;$avg&lt;/code&gt;, &lt;code&gt;$min&lt;/code&gt;, &lt;code&gt;$max&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Math operators for groups&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Example: Average Age by Country
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.aggregate([
  { $group: { _id: "$country", avgAge: { $avg: "$age" } } }
]).then(console.log);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Real-World Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Report generation (sales per region)&lt;/li&gt;
&lt;li&gt;Filtering + transforming dashboards&lt;/li&gt;
&lt;li&gt;Grouping comments by user&lt;/li&gt;
&lt;li&gt;Creating charts and summaries&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Notes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Aggregations bypass Mongoose schema rules.&lt;/li&gt;
&lt;li&gt;Always validate data before running aggregations.&lt;/li&gt;
&lt;li&gt;Aggregation is read-only—use for querying, not updating.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aggregation helps you unlock deep insights from your data without writing complex backend logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lean Queries in Mongoose
&lt;/h3&gt;

&lt;p&gt;By default, Mongoose returns &lt;strong&gt;full Mongoose documents&lt;/strong&gt; with lots of features like getters, setters, virtuals, and instance methods. But sometimes, you just want &lt;strong&gt;plain JavaScript objects&lt;/strong&gt; for performance.&lt;/p&gt;

&lt;p&gt;That’s where &lt;code&gt;.lean()&lt;/code&gt; comes in.&lt;/p&gt;




&lt;h4&gt;
  
  
  What is &lt;code&gt;.lean()&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;Calling &lt;code&gt;.lean()&lt;/code&gt; tells Mongoose to &lt;strong&gt;skip&lt;/strong&gt; the document enhancement and return &lt;strong&gt;plain JSON&lt;/strong&gt; objects directly from MongoDB.&lt;/p&gt;




&lt;h4&gt;
  
  
  Example: Using &lt;code&gt;.lean()&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find({ isActive: true }).lean().then(users =&amp;gt; {
  console.log(typeof users[0]); // "object"
  console.log(users[0] instanceof mongoose.Document); // false
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Why use &lt;code&gt;.lean()&lt;/code&gt;?
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Benefit&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Faster queries&lt;/td&gt;
&lt;td&gt;No conversion to Mongoose document&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lower memory usage&lt;/td&gt;
&lt;td&gt;Especially useful in large queries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Better for APIs&lt;/td&gt;
&lt;td&gt;Lightweight JSON responses&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  When NOT to Use .lean()
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If you need to use virtuals, getters/setters, or instance methods&lt;/li&gt;
&lt;li&gt;If you rely on schema validation logic&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Tip: .lean() with .populate()
&lt;/h4&gt;

&lt;p&gt;Works fine! You can still populate referenced docs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Post.find().populate("author").lean().then(posts =&amp;gt; {
  console.log(posts[0].author.name);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Compare Performance
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Without lean (Mongoose doc)
const normal = await User.find();

// With lean (plain object)
const fast = await User.find().lean();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using .lean() gives you a huge performance boost for read-heavy applications, especially APIs and dashboards.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mongoose Transactions (ACID)
&lt;/h3&gt;

&lt;p&gt;MongoDB supports &lt;strong&gt;multi-document ACID transactions&lt;/strong&gt; on replica sets and sharded clusters. Mongoose enables you to use this feature with &lt;strong&gt;sessions&lt;/strong&gt; to ensure operations are all-or-nothing.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use Transactions?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Ensure &lt;strong&gt;atomicity&lt;/strong&gt; (either all changes happen or none)&lt;/li&gt;
&lt;li&gt;Maintain &lt;strong&gt;data integrity&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Handle &lt;strong&gt;multi-document updates&lt;/strong&gt; safely&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Starting a Transaction in Mongoose
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const session = await mongoose.startSession();
session.startTransaction();

try {
  await User.create([{ name: "Alice" }], { session });
  await Post.create([{ title: "Hello", author: "Alice" }], { session });

  await session.commitTransaction();  // ✅ Commit changes
} catch (err) {
  await session.abortTransaction();  // ❌ Rollback on error
  console.error(err);
} finally {
  session.endSession();              // 🧹 Always clean up
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  With async/await
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const runTransaction = async () =&amp;gt; {
  const session = await mongoose.startSession();
  try {
    await session.withTransaction(async () =&amp;gt; {
      const user = await User.create([{ name: "John" }], { session });
      const post = await Post.create([{ title: "Welcome", author: user[0]._id }], { session });
    });
  } catch (err) {
    console.error("Transaction failed:", err);
  } finally {
    session.endSession();
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Requirements
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;MongoDB 4.0+ and replica set enabled (even a single-node replica set in dev)&lt;/li&gt;
&lt;li&gt;Use { session } in each query involved in the transaction&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Real-World Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Creating a user + default profile&lt;/li&gt;
&lt;li&gt;Placing an order + updating inventory&lt;/li&gt;
&lt;li&gt;Booking system: lock seat + confirm payment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Transactions are key for building reliable, enterprise-grade applications with MongoDB.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mongoose Error Handling
&lt;/h3&gt;

&lt;p&gt;Robust error handling is essential for building reliable applications. Mongoose provides a variety of error types to help identify and respond to issues.&lt;/p&gt;




&lt;h4&gt;
  
  
  Common Mongoose Errors
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Error Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ValidationError&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Schema validation failed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CastError&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Invalid ObjectId or data type&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MongoServerError&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Duplicate key, indexing issues, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DocumentNotFoundError&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When using &lt;code&gt;.orFail()&lt;/code&gt; and no document is found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DisconnectedError&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Mongoose lost connection to MongoDB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Example: Basic Try-Catch Block
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
  const user = await User.create({ email: "invalid" });
} catch (err) {
  console.error("Something went wrong:", err.message);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Handling ValidationError
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
  await User.create({ name: "" }); // name is required
} catch (err) {
  if (err.name === "ValidationError") {
    console.error("Validation failed:", err.errors);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Handling Invalid ObjectId (CastError)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
  const user = await User.findById("invalid_id");
} catch (err) {
  if (err.name === "CastError") {
    console.error("Invalid ID format!");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Handling Duplicate Key (e.g., email already exists)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
  await User.create({ email: "test@example.com" }); // email is unique
} catch (err) {
  if (err.code === 11000) {
    console.error("Duplicate key error:", err.keyValue);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Tips for Production
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Avoid leaking sensitive error info to users.&lt;/li&gt;
&lt;li&gt;Log full error stacks to your server logs.&lt;/li&gt;
&lt;li&gt;Use asyncHandler or error-handling middleware in Express.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Optional: Using .orFail()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await User.findById(userId).orFail(new Error("User not found"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Proper error handling makes your app more secure, stable, and easier to debug.&lt;/p&gt;

&lt;h3&gt;
  
  
  Plugins in Mongoose
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Plugins&lt;/strong&gt; are reusable pieces of schema logic in Mongoose. They allow you to DRY (Don't Repeat Yourself) your code by abstracting repeated patterns into reusable functions.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use Plugins?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Add timestamps automatically&lt;/li&gt;
&lt;li&gt;Enforce soft deletes&lt;/li&gt;
&lt;li&gt;Add pagination or search functionality&lt;/li&gt;
&lt;li&gt;Encrypt fields like passwords&lt;/li&gt;
&lt;li&gt;Audit log tracking&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Creating a Simple Plugin
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// plugins/timestampPlugin.js
module.exports = function timestampPlugin(schema) {
  schema.add({
    createdAt: { type: Date, default: Date.now },
    updatedAt: { type: Date }
  });

  schema.pre("save", function (next) {
    this.updatedAt = Date.now();
    next();
  });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using the Plugin in a Schema
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mongoose = require("mongoose");
const timestampPlugin = require("./plugins/timestampPlugin");

const blogSchema = new mongoose.Schema({
  title: String,
  content: String
});

blogSchema.plugin(timestampPlugin); // 👈 Apply plugin here

const Blog = mongoose.model("Blog", blogSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Plugin Name&lt;/th&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mongoose-paginate-v2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Adds pagination to models&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mongoose-unique-validator&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Validates uniqueness before saving&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mongoose-delete&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Soft delete functionality&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mongoose-autopopulate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Auto-populates refs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mongoose-slug-generator&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Generates URL slugs from titles&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Install via npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install mongoose-paginate-v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use in schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const paginate = require("mongoose-paginate-v2");
schema.plugin(paginate);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best Practices&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep plugins modular and reusable&lt;/li&gt;
&lt;li&gt;Prefix custom plugins with mongoose- if publishing&lt;/li&gt;
&lt;li&gt;Avoid plugin conflicts (e.g., two plugins modifying the same hook)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mongoose plugins supercharge your schemas by keeping code clean, DRY, and powerful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mongoose Performance Optimization Tips
&lt;/h3&gt;

&lt;p&gt;As your app scales, it’s essential to make your MongoDB and Mongoose operations as efficient as possible. Here are practical tips to improve performance.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Use &lt;code&gt;.lean()&lt;/code&gt; for Read-Only Queries
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find({ isActive: true }).lean();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Returns plain JS objects (not full Mongoose documents)&lt;/p&gt;

&lt;p&gt;Faster and less memory usage&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Index Your Queries
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userSchema = new mongoose.Schema({
  email: { type: String, index: true }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add indexes on frequently queried fields&lt;/li&gt;
&lt;li&gt;Use explain() to check query performance&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Select Only Needed Fields
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find().select("name email");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Avoid fetching entire documents&lt;/li&gt;
&lt;li&gt;Reduces network and memory usage&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Pagination Instead of .skip() on Large Datasets
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;.skip() can be slow with large offsets&lt;/li&gt;
&lt;li&gt;Prefer range-based pagination using _id or timestamps
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find({ _id: { $gt: lastId } }).limit(10);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Use bulkWrite for Batch Operations
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model.bulkWrite([
  { updateOne: { filter: { _id }, update: { $set: { field: value } } } },
  { deleteOne: { filter: { _id } } }
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Ideal for large-scale updates/deletes&lt;/li&gt;
&lt;li&gt;Much faster than running individual operations&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  6. Avoid Unnecessary Middleware &amp;amp; Virtuals
&lt;/h4&gt;

&lt;p&gt;Disable unused features if performance matters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const schema = new mongoose.Schema({...}, { virtuals: false });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  7. Monitor Query Performance
&lt;/h4&gt;

&lt;p&gt;Use .explain() to see query execution stats&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.find({ email: "a@example.com" }).explain("executionStats");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  8. Use Connection Pooling in Production
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoose.connect(MONGO_URI, {
  maxPoolSize: 10, // Controls concurrent operations
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Bonus: Enable Mongoose Debugging
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoose.set("debug", true);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Logs queries to console&lt;/li&gt;
&lt;li&gt;Useful for development&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Optimizing Mongoose is about writing smarter queries, reducing load, and using MongoDB’s full power.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mongoose Deployment &amp;amp; Production Tips
&lt;/h3&gt;

&lt;p&gt;Before going live with your Node.js + Mongoose app, make sure your deployment is secure, stable, and optimized.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Use Environment Variables
&lt;/h4&gt;

&lt;p&gt;Never hardcode credentials or database URLs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .env file
MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/mydb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require("dotenv").config();
mongoose.connect(process.env.MONGO_URI);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Use Connection Options
&lt;/h4&gt;

&lt;p&gt;Fine-tune performance and reliability with options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoose.connect(process.env.MONGO_URI, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  maxPoolSize: 10, // Connection pool
  serverSelectionTimeoutMS: 5000 // Fail fast on bad DB
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Enable Monitoring
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use services like:&lt;/li&gt;
&lt;li&gt;MongoDB Atlas performance tab&lt;/li&gt;
&lt;li&gt;New Relic, Datadog, PM2 Metrics
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoose.set("debug", true) (development only)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Use Replica Set for Production
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Enables transactions&lt;/li&gt;
&lt;li&gt;Improves availability and fault tolerance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even in dev:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongod --replSet rs0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rs.initiate()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Error Handling Middleware (Express)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use((err, req, res, next) =&amp;gt; {
  console.error(err.stack);
  res.status(500).send("Something went wrong!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Prevents crashes&lt;/li&gt;
&lt;li&gt;Centralizes error responses&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  6. Secure Your Database
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Don’t expose MongoDB publicly&lt;/li&gt;
&lt;li&gt;Whitelist IPs in MongoDB Atlas&lt;/li&gt;
&lt;li&gt;Use SSL/TLS for connections&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  7. Backup &amp;amp; Disaster Recovery
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Set up automatic backups (Atlas supports this)&lt;/li&gt;
&lt;li&gt;Test your restore process&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  8. Restart Strategies
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use process managers like:&lt;/li&gt;
&lt;li&gt;PM2&lt;/li&gt;
&lt;li&gt;Docker containers + health checks&lt;/li&gt;
&lt;li&gt;Auto-restart on crashes&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  9. Use Linting &amp;amp; Logging
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Lint your code with ESLint&lt;/li&gt;
&lt;li&gt;Log errors and queries for audit
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install morgan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  10. Testing Before Shipping
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use jest, supertest, or mocha to test routes and DB logic&lt;/li&gt;
&lt;li&gt;Test all edge cases before deploying&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Solid Mongoose apps are built not just on code, but on strong deployment practices and monitoring systems.&lt;/p&gt;




&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Congratulations on making it to the end of this comprehensive guide on &lt;strong&gt;MongoDB and Mongoose&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;By now, you’ve covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MongoDB fundamentals (CRUD, BSON, documents, collections)
&lt;/li&gt;
&lt;li&gt;Mongoose setup and schema modeling
&lt;/li&gt;
&lt;li&gt;Data validations and error handling
&lt;/li&gt;
&lt;li&gt;Middleware, plugins, transactions, and performance tips
&lt;/li&gt;
&lt;li&gt;Real-world backend structure using Express + MongoDB
&lt;/li&gt;
&lt;li&gt;Deployment best practices and production strategies&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  What’s Next?
&lt;/h4&gt;

&lt;p&gt;Now that you’ve got a strong foundation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start building your own backend projects with MongoDB&lt;/li&gt;
&lt;li&gt;Try out more advanced features like &lt;strong&gt;aggregation pipelines&lt;/strong&gt;, &lt;strong&gt;virtuals&lt;/strong&gt;, and &lt;strong&gt;MongoDB Atlas Triggers&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Experiment with &lt;strong&gt;caching&lt;/strong&gt;, &lt;strong&gt;rate limiting&lt;/strong&gt;, and &lt;strong&gt;authorization layers&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Stay Connected
&lt;/h4&gt;

&lt;p&gt;If this guide helped you, feel free to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⭐ Bookmark &amp;amp; Share it with fellow developers
&lt;/li&gt;
&lt;li&gt;🗣 Drop your thoughts, suggestions, or questions in the comments
&lt;/li&gt;
&lt;li&gt;🛠️ Follow me for upcoming full-stack guides and project tutorials&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;💬 &lt;strong&gt;“The best way to learn is to build.”&lt;/strong&gt; So go ahead — spin up a project, explore real datasets, and turn this knowledge into something awesome!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;Keep building. Keep learning. See you in the next one!&lt;/strong&gt; 👋&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>SQL for Everyone: The Ultimate Starter Guide</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Thu, 05 Jun 2025 19:47:27 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/sql-for-everyone-the-ultimate-starter-guide-1h3d</link>
      <guid>https://dev.to/_bhupeshk_/sql-for-everyone-the-ultimate-starter-guide-1h3d</guid>
      <description>&lt;p&gt;Welcome to your all-in-one SQL learning journey! 🚀&lt;/p&gt;

&lt;p&gt;Whether you're just starting with databases or revising for a backend development project, this guide will help you master SQL from the ground up.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Topics Covered
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;📌 What is SQL? Why use databases?&lt;/li&gt;
&lt;li&gt;🧱 Tables, Data Types, Keys &amp;amp; Constraints&lt;/li&gt;
&lt;li&gt;✍️ INSERT, UPDATE, DELETE&lt;/li&gt;
&lt;li&gt;🔍 SELECT, WHERE, ORDER BY, GROUP BY, HAVING&lt;/li&gt;
&lt;li&gt;🎯 Aggregate Functions&lt;/li&gt;
&lt;li&gt;🔧 ALTER, TRUNCATE, SQL_SAFE_UPDATES&lt;/li&gt;
&lt;li&gt;🔗 JOINs (INNER, LEFT, RIGHT, FULL, SELF)&lt;/li&gt;
&lt;li&gt;🌀 Subqueries&lt;/li&gt;
&lt;li&gt;👓 Views&lt;/li&gt;
&lt;li&gt;⚡ Indexes&lt;/li&gt;
&lt;li&gt;🔐 Transactions &amp;amp; ACID principles&lt;/li&gt;
&lt;li&gt;🎭 CASE Statements&lt;/li&gt;
&lt;li&gt;📚 UNION vs UNION ALL&lt;/li&gt;
&lt;li&gt;🧠 EXISTS vs IN&lt;/li&gt;
&lt;li&gt;🔍 BETWEEN, LIKE, IS NULL&lt;/li&gt;
&lt;li&gt;🏗️ Common Table Expressions (CTEs) with &lt;code&gt;WITH&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 Who Is This For?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Aspiring backend or full-stack developers&lt;/li&gt;
&lt;li&gt;Students working on SQL-based projects&lt;/li&gt;
&lt;li&gt;Engineers preparing for interviews&lt;/li&gt;
&lt;li&gt;Anyone who wants to write faster, cleaner, and more efficient SQL queries&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 How to Use
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;💻 Copy code snippets and run them in your SQL environment (MySQL, PostgreSQL, etc.)&lt;/li&gt;
&lt;li&gt;🔄 Practice with real datasets or mock tables&lt;/li&gt;
&lt;li&gt;🧠 Use this guide as your personal SQL reference handbook&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Let’s break it down into simple concepts, illustrated examples, and hands-on practice to &lt;strong&gt;build your confidence step by step&lt;/strong&gt;. Ready? Let’s dive in! ⛏️&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Database?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;database&lt;/strong&gt; is an organized collection of data that can be &lt;strong&gt;easily accessed, managed, and updated&lt;/strong&gt;. It allows software applications to &lt;strong&gt;store, retrieve, and manipulate data&lt;/strong&gt; efficiently.&lt;/p&gt;




&lt;h4&gt;
  
  
  Key Features of a Database:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Persistent storage&lt;/strong&gt;: Data is saved permanently (not lost after app closes).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structured format&lt;/strong&gt;: Organized using tables, collections, schemas, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient querying&lt;/strong&gt;: Retrieve and filter data using query languages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalable &amp;amp; secure&lt;/strong&gt;: Can handle large amounts of data with access control.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Common Types of Databases:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Examples&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Relational (SQL)&lt;/td&gt;
&lt;td&gt;Uses tables with rows &amp;amp; columns&lt;/td&gt;
&lt;td&gt;MySQL, PostgreSQL, SQLite&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NoSQL&lt;/td&gt;
&lt;td&gt;Flexible schema, often document-based&lt;/td&gt;
&lt;td&gt;MongoDB, Firebase, Redis&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;In-Memory&lt;/td&gt;
&lt;td&gt;Data stored in RAM for fast access&lt;/td&gt;
&lt;td&gt;Redis, Memcached&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Graph&lt;/td&gt;
&lt;td&gt;Stores data as nodes and edges (relationships)&lt;/td&gt;
&lt;td&gt;Neo4j&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Why Use a Database?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Store user info (login/signup)&lt;/li&gt;
&lt;li&gt;Manage blog posts, products, orders, etc.&lt;/li&gt;
&lt;li&gt;Persist app data across sessions&lt;/li&gt;
&lt;li&gt;Enable data analysis, reports, and business logic&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Example Use Case
&lt;/h4&gt;

&lt;p&gt;An e-commerce app uses a database to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save user accounts and passwords&lt;/li&gt;
&lt;li&gt;Store product information and inventory&lt;/li&gt;
&lt;li&gt;Track orders and payments&lt;/li&gt;
&lt;li&gt;Display customer reviews&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Databases are the backbone of modern applications — allowing apps to be dynamic, data-driven, and scalable!&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  SQL vs NoSQL Databases
&lt;/h3&gt;

&lt;p&gt;Choosing the right type of database is crucial for building scalable and efficient applications. Here's a breakdown of &lt;strong&gt;SQL (Relational)&lt;/strong&gt; vs &lt;strong&gt;NoSQL (Non-Relational)&lt;/strong&gt; databases:&lt;/p&gt;




&lt;h4&gt;
  
  
  Key Differences
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;SQL (Relational)&lt;/th&gt;
&lt;th&gt;NoSQL (Non-Relational)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;📐 Structure&lt;/td&gt;
&lt;td&gt;Table-based (rows &amp;amp; columns)&lt;/td&gt;
&lt;td&gt;Document, key-value, graph, or wide-column&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📋 Schema&lt;/td&gt;
&lt;td&gt;Fixed schema (predefined)&lt;/td&gt;
&lt;td&gt;Dynamic schema (flexible)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;💬 Query Language&lt;/td&gt;
&lt;td&gt;SQL (Structured Query Language)&lt;/td&gt;
&lt;td&gt;Varies: MongoDB uses JSON-like queries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📶 Relationships&lt;/td&gt;
&lt;td&gt;Strong support for joins &amp;amp; relations&lt;/td&gt;
&lt;td&gt;Weak or no join support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚙️ Scalability&lt;/td&gt;
&lt;td&gt;Vertical (scale-up: stronger machine)&lt;/td&gt;
&lt;td&gt;Horizontal (scale-out: more machines)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧩 Best For&lt;/td&gt;
&lt;td&gt;Complex queries, ACID compliance&lt;/td&gt;
&lt;td&gt;Large datasets, real-time apps, flexibility&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📚 Examples&lt;/td&gt;
&lt;td&gt;MySQL, PostgreSQL, SQLite, MS SQL Server&lt;/td&gt;
&lt;td&gt;MongoDB, Firebase, CouchDB, Redis&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  When to Use SQL
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Banking, finance, or systems needing strong data integrity&lt;/li&gt;
&lt;li&gt;Apps requiring multi-table joins&lt;/li&gt;
&lt;li&gt;Structured data with clear relationships&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  When to Use NoSQL
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Real-time analytics or big data&lt;/li&gt;
&lt;li&gt;Content management systems, IoT, or chat apps&lt;/li&gt;
&lt;li&gt;Rapid development with changing requirements&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Example Comparison
&lt;/h4&gt;

&lt;h3&gt;
  
  
  SQL Table (User)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;email&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;&lt;a href="mailto:alice@mail.com"&gt;alice@mail.com&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  NoSQL Document (MongoDB)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "_id": "1",
  "name": "Alice",
  "email": "alice@mail.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is SQL?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;SQL (Structured Query Language)&lt;/strong&gt; is a standard programming language used to &lt;strong&gt;manage and manipulate relational databases&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Key Features
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Create and modify database &lt;strong&gt;tables&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Insert, update, and delete &lt;strong&gt;data&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Retrieve specific data using &lt;strong&gt;queries&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Enforce &lt;strong&gt;constraints&lt;/strong&gt;, relationships, and data integrity&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  SQL is Used For:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;SQL Command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Create Table&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CREATE TABLE&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Insert Data&lt;/td&gt;
&lt;td&gt;&lt;code&gt;INSERT INTO&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Retrieve Data&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SELECT&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Update Data&lt;/td&gt;
&lt;td&gt;&lt;code&gt;UPDATE&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delete Data&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DELETE&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filter Data&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;LIKE&lt;/code&gt;, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Join Tables&lt;/td&gt;
&lt;td&gt;&lt;code&gt;JOIN&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Create a table
CREATE TABLE users (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Insert data
INSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@mail.com');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Retrieve data
SELECT * FROM users WHERE name = 'Alice';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Table in SQL
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;table&lt;/strong&gt; in SQL is a structured format to store &lt;strong&gt;rows of data&lt;/strong&gt; in &lt;strong&gt;columns&lt;/strong&gt;, like a spreadsheet. Each table represents a &lt;strong&gt;specific entity&lt;/strong&gt; — such as users, products, or orders.&lt;/p&gt;




&lt;h4&gt;
  
  
  Table Structure
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rows&lt;/strong&gt;: Each row (record) holds data for one item.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Columns&lt;/strong&gt;: Each column represents a specific attribute (field) of the item.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Primary Key&lt;/strong&gt;: Uniquely identifies each row.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Example Table: &lt;code&gt;users&lt;/code&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;email&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;&lt;a href="mailto:alice@mail.com"&gt;alice@mail.com&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;&lt;a href="mailto:bob@mail.com"&gt;bob@mail.com&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  SQL Syntax: Create Table
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Our First Database in SQL
&lt;/h3&gt;

&lt;p&gt;Let’s create our first SQL database and table! This is your first real step into working with relational databases like MySQL, PostgreSQL, or SQLite.&lt;/p&gt;




&lt;h4&gt;
  
  
  Step 1: Create a Database
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE myAppDB;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Use the Database
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USE myAppDB;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Switches your current session to the newly created database.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Create a Table
&lt;/h4&gt;

&lt;p&gt;Let’s create a users table to store user information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(100) UNIQUE NOT NULL,
  age INT
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4: Insert Data into the Table
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO users (name, email, age)
VALUES ('Alice', 'alice@example.com', 25),
       ('Bob', 'bob@example.com', 30);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 5: View Data
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 This retrieves all records from the users table.&lt;/p&gt;

&lt;h1&gt;
  
  
  📋 Our First Table in SQL
&lt;/h1&gt;

&lt;p&gt;Now that we’ve created our first database, let’s build our &lt;strong&gt;first table&lt;/strong&gt; to store data!&lt;/p&gt;




&lt;h3&gt;
  
  
  What is a Table?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;table&lt;/strong&gt; is a collection of related data organized in &lt;strong&gt;rows and columns&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Each column has a name and a &lt;strong&gt;data type&lt;/strong&gt; (e.g., text, number, date).&lt;/p&gt;


&lt;h4&gt;
  
  
  Step-by-Step: Create a &lt;code&gt;users&lt;/code&gt; Table
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(100) UNIQUE NOT NULL,
  age INT,
  created_at DATE
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Database Queries in SQL
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;query&lt;/strong&gt; is a request to the database to &lt;strong&gt;retrieve, insert, update, or delete data&lt;/strong&gt;. SQL provides different commands to perform these actions efficiently.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SELECT&lt;/td&gt;
&lt;td&gt;Retrieve data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;INSERT&lt;/td&gt;
&lt;td&gt;Add new data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UPDATE&lt;/td&gt;
&lt;td&gt;Modify existing data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DELETE&lt;/td&gt;
&lt;td&gt;Remove data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WHERE&lt;/td&gt;
&lt;td&gt;Filter data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ORDER BY&lt;/td&gt;
&lt;td&gt;Sort results&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LIMIT&lt;/td&gt;
&lt;td&gt;Limit number of rows&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  CREATE TABLE in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;CREATE TABLE&lt;/code&gt; statement is used to define a new table and its structure in a relational database.&lt;/p&gt;


&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE table_name (
  column1 datatype constraints,
  column2 datatype constraints,
  ...
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Example: Creating a users Table
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(100) UNIQUE NOT NULL,
  age INT,
  created_at DATE
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Column Breakdown&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Column Name&lt;/th&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;th&gt;Constraints&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;INT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;PRIMARY KEY&lt;/code&gt;, &lt;code&gt;AUTO_INCREMENT&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Unique ID for each user&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;VARCHAR(100)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Required name field&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;email&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;VARCHAR(100)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;UNIQUE&lt;/code&gt;, &lt;code&gt;NOT NULL&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Must be unique and not empty&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;age&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;INT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;(optional)&lt;/td&gt;
&lt;td&gt;User's age&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;created_at&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DATE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;(optional)&lt;/td&gt;
&lt;td&gt;Date of account creation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Common Constraints&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Constraint&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PRIMARY KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Uniquely identifies each row&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Field cannot be empty&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UNIQUE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Prevents duplicate values in the column&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AUTO_INCREMENT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Automatically increases the number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DEFAULT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sets a default value&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  SQL Data Types
&lt;/h3&gt;

&lt;p&gt;When creating tables in SQL, every column must be assigned a &lt;strong&gt;data type&lt;/strong&gt; that defines what kind of data it can store — such as numbers, text, dates, or booleans.&lt;/p&gt;


&lt;h4&gt;
  
  
  Numeric Data Types
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;INT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Integer number (whole numbers)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SMALLINT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Smaller range of integer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;BIGINT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Very large integers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DECIMAL(p,s)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fixed-point numbers (e.g., money)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;FLOAT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Approximate floating-point number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DOUBLE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Double precision float&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  String/Text Data Types
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CHAR(n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fixed-length string (e.g., CHAR(10))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;VARCHAR(n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Variable-length string (e.g., VARCHAR(100))&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TEXT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Large text field&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Date and Time Data Types
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DATE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Date only (YYYY-MM-DD)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TIME&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Time only (HH:MM:SS)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DATETIME&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Date and time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TIMESTAMP&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Auto-records current time&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Boolean Data Type
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;BOOLEAN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;TRUE or FALSE&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Some databases (like MySQL) use &lt;code&gt;TINYINT(1)&lt;/code&gt; for &lt;code&gt;BOOLEAN&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h4&gt;
  
  
  Other Data Types (Advanced Use)
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ENUM&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Set of predefined values&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;BLOB&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Binary Large Object (images/files)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;JSON&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores JSON-formatted data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UUID&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Universally Unique Identifier&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example: Using Data Types
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE products (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  price DECIMAL(10, 2),
  in_stock BOOLEAN DEFAULT true,
  created_at DATETIME
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  🔐 What are SQL Constraints?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt; in SQL are rules applied to columns in a table to &lt;strong&gt;enforce data integrity&lt;/strong&gt;, &lt;strong&gt;restrict invalid input&lt;/strong&gt;, and maintain &lt;strong&gt;accuracy and reliability&lt;/strong&gt; in the database.&lt;/p&gt;


&lt;h3&gt;
  
  
  Common SQL Constraints
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Constraint&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PRIMARY KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Uniquely identifies each record in a table&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;FOREIGN KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Links a column to the &lt;code&gt;PRIMARY KEY&lt;/code&gt; of another table (maintains relationships)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ensures a column &lt;strong&gt;cannot&lt;/strong&gt; have a &lt;code&gt;NULL&lt;/code&gt; (empty) value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UNIQUE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ensures &lt;strong&gt;all values in a column are different&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DEFAULT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sets a &lt;strong&gt;default value&lt;/strong&gt; if none is provided&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CHECK&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Limits values based on a condition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AUTO_INCREMENT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Automatically increases value for new records (commonly used for IDs)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example: Applying Constraints
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(100) UNIQUE,
  age INT CHECK (age &amp;gt;= 18),
  country VARCHAR(50) DEFAULT 'Canada'
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  FOREIGN KEY Example
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE orders (
  order_id INT PRIMARY KEY,
  user_id INT,
  FOREIGN KEY (user_id) REFERENCES users(id)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Why Use Constraints?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Prevent invalid data (e.g., negative age, duplicate emails)&lt;/li&gt;
&lt;li&gt;Ensure relationships between tables stay consistent&lt;/li&gt;
&lt;li&gt;Provide fallback values with DEFAULT&lt;/li&gt;
&lt;li&gt;Avoid NULL errors and enforce required fields&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Key Constraints in SQL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Key constraints&lt;/strong&gt; are special rules that help &lt;strong&gt;uniquely identify rows&lt;/strong&gt; and &lt;strong&gt;maintain relationships&lt;/strong&gt; between tables in a database.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. PRIMARY KEY
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Uniquely identifies each record in a table&lt;/li&gt;
&lt;li&gt;Cannot have &lt;code&gt;NULL&lt;/code&gt; or duplicate values&lt;/li&gt;
&lt;li&gt;Usually used on the &lt;code&gt;id&lt;/code&gt; column
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY,
  name VARCHAR(100)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can only have one PRIMARY KEY per table (can be a single column or a combination of columns).&lt;/p&gt;
&lt;h4&gt;
  
  
  2. FOREIGN KEY
&lt;/h4&gt;

&lt;p&gt;Creates a relationship between two tables&lt;/p&gt;

&lt;p&gt;The value must match a PRIMARY KEY in another table&lt;/p&gt;

&lt;p&gt;Ensures referential integrity&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE orders (
  order_id INT PRIMARY KEY,
  user_id INT,
  FOREIGN KEY (user_id) REFERENCES users(id)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If a user_id in orders doesn’t exist in the users table, the database will throw an error.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  3. COMPOSITE KEY
&lt;/h4&gt;

&lt;p&gt;A PRIMARY KEY that consists of two or more columns&lt;/p&gt;

&lt;p&gt;Ensures uniqueness across the combination of values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE enrollments (
  student_id INT,
  course_id INT,
  PRIMARY KEY (student_id, course_id)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Useful when no single column is unique, but a combination is.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Primary Key vs Foreign Key in SQL
&lt;/h3&gt;

&lt;p&gt;Both &lt;strong&gt;Primary Keys&lt;/strong&gt; and &lt;strong&gt;Foreign Keys&lt;/strong&gt; are types of &lt;strong&gt;constraints&lt;/strong&gt; used to manage relationships and ensure data integrity in relational databases.&lt;/p&gt;




&lt;h4&gt;
  
  
  Primary Key
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Uniquely identifies&lt;/strong&gt; each row in a table.&lt;/li&gt;
&lt;li&gt;Must be &lt;strong&gt;unique&lt;/strong&gt; and &lt;strong&gt;NOT NULL&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;A table can have &lt;strong&gt;only one&lt;/strong&gt; primary key.&lt;/li&gt;
&lt;li&gt;Often used on the &lt;code&gt;id&lt;/code&gt; column.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;id is the primary key — each user will have a unique ID.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Foreign Key
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Establishes a link between two tables.&lt;/li&gt;
&lt;li&gt;Points to a primary key in another table.&lt;/li&gt;
&lt;li&gt;Ensures referential integrity (no invalid references).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE orders (
  order_id INT PRIMARY KEY,
  user_id INT,
  FOREIGN KEY (user_id) REFERENCES users(id)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;user_id in orders references id in users.&lt;br&gt;
You can’t insert an order with a user_id that doesn’t exist in users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  INSERT INTO in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;INSERT INTO&lt;/code&gt; statement is used to &lt;strong&gt;add new rows of data&lt;/strong&gt; into an existing table.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Inserting into users Table
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE users (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO users (id, name, email)
VALUES (1, 'Alice', 'alice@mail.com');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always match column names with their respective values.&lt;/li&gt;
&lt;li&gt;You can omit columns that allow NULL or have default values.&lt;/li&gt;
&lt;li&gt;If you’re using AUTO_INCREMENT for id, you can skip it:&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  SELECT Command in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;SELECT&lt;/code&gt; command is used to &lt;strong&gt;retrieve data&lt;/strong&gt; from a database table. It's one of the most commonly used SQL commands.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column1, column2, ...
FROM table_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Selecting from a users Table
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Returns all columns and rows from the users table.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Select Specific Columns
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, email FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Fetches only the name and email columns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  SQL &lt;code&gt;WHERE&lt;/code&gt; Clause
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;WHERE&lt;/code&gt; clause in SQL is used to &lt;strong&gt;filter records&lt;/strong&gt; based on specific conditions.&lt;br&gt;&lt;br&gt;
It helps retrieve &lt;strong&gt;only the rows that meet a defined criteria&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column1, column2, ...
FROM table_name
WHERE condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Example: Filter Users by Age
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users
WHERE age &amp;gt; 25;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Returns users older than 25.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Operators in SQL &lt;code&gt;WHERE&lt;/code&gt; Clause
&lt;/h3&gt;

&lt;p&gt;Operators in the &lt;code&gt;WHERE&lt;/code&gt; clause allow you to &lt;strong&gt;filter rows&lt;/strong&gt; based on conditions. These can include comparisons, pattern matching, null checks, and logical combinations.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. &lt;strong&gt;Comparison Operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age = 30&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;name != 'Alice'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not equal (alternative)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;email &amp;lt;&amp;gt; 'x@mail.com'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;salary &amp;gt; 50000&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age &amp;lt; 18&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age &amp;gt;= 21&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;score &amp;lt;= 100&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  2. &lt;strong&gt;Logical Operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AND&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Both conditions must be true&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age &amp;gt; 25 AND country = 'Canada'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;OR&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;At least one condition must be true&lt;/td&gt;
&lt;td&gt;&lt;code&gt;city = 'Delhi' OR city = 'Mumbai'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NOT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reverses the result of a condition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;NOT (age &amp;lt; 18)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  3. &lt;strong&gt;Special Operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;BETWEEN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Value within a range (inclusive)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age BETWEEN 20 AND 30&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Match any value in a list&lt;/td&gt;
&lt;td&gt;&lt;code&gt;country IN ('India', 'Canada', 'USA')&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;LIKE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Pattern match using wildcards&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;name LIKE 'A%'&lt;/code&gt; (starts with 'A')&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IS NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks for NULL&lt;/td&gt;
&lt;td&gt;&lt;code&gt;email IS NULL&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IS NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks for non-NULL&lt;/td&gt;
&lt;td&gt;&lt;code&gt;email IS NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Pattern Matching with &lt;code&gt;LIKE&lt;/code&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'A%'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Starts with A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'%z'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ends with z&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'%test%'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains 'test' anywhere&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'____'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exactly 4 characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'A_C'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Starts with A, any one char, ends with C&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Examples
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Users older than 30
SELECT * FROM users WHERE age &amp;gt; 30;

-- Users named Alice or Bob
SELECT * FROM users WHERE name IN ('Alice', 'Bob');

-- Users with no email
SELECT * FROM users WHERE email IS NULL;

-- Users whose name starts with J
SELECT * FROM users WHERE name LIKE 'J%';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Frequently Used SQL Operators
&lt;/h3&gt;

&lt;p&gt;These are the most commonly used operators when writing SQL queries, especially in the &lt;code&gt;WHERE&lt;/code&gt; clause for filtering data.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Comparison Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age = 25&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;city != 'Delhi'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not equal to (same as &lt;code&gt;!=&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;status &amp;lt;&amp;gt; 'Active'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;price &amp;gt; 100&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age &amp;lt; 18&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;score &amp;gt;= 75&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;stock &amp;lt;= 10&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  2. Logical Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AND&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Both conditions must be true&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age &amp;gt; 18 AND country = 'India'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;OR&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;At least one condition must be true&lt;/td&gt;
&lt;td&gt;&lt;code&gt;state = 'NY' OR state = 'CA'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NOT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reverses the condition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;NOT (category = 'Electronics')&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  3. Special Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;BETWEEN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Within a range&lt;/td&gt;
&lt;td&gt;&lt;code&gt;salary BETWEEN 50000 AND 80000&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Match against a list&lt;/td&gt;
&lt;td&gt;&lt;code&gt;department IN ('HR', 'IT', 'Sales')&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;LIKE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Pattern matching&lt;/td&gt;
&lt;td&gt;&lt;code&gt;name LIKE 'A%'&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IS NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks for empty (null) values&lt;/td&gt;
&lt;td&gt;&lt;code&gt;email IS NULL&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IS NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks for non-null values&lt;/td&gt;
&lt;td&gt;&lt;code&gt;email IS NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Pattern Matching with &lt;code&gt;LIKE&lt;/code&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'A%'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Starts with A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'%z'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ends with z&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'%tech%'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains 'tech' anywhere&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;'____'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exactly 4 characters&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example Usage
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM products
WHERE category = 'Electronics' AND price &amp;gt; 1000;

SELECT * FROM users
WHERE name LIKE 'J%' AND city IN ('Toronto', 'Vancouver');

SELECT * FROM orders
WHERE delivery_date IS NOT NULL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  LIMIT Clause in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;LIMIT&lt;/code&gt; clause is used to &lt;strong&gt;restrict the number of rows&lt;/strong&gt; returned by a query.&lt;br&gt;&lt;br&gt;
It's especially useful for pagination or when previewing large datasets.&lt;/p&gt;


&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column1, column2, ...
FROM table_name
LIMIT number;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Example: Get First 5 Rows
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users
LIMIT 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Returns only the first 5 rows from the users table.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  LIMIT with OFFSET
&lt;/h3&gt;

&lt;p&gt;Use OFFSET to skip a specific number of rows before starting to return rows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users
LIMIT 5 OFFSET 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Skips the first 10 rows and returns the next 5.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Pagination Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Page 1: First 10 results
SELECT * FROM users LIMIT 10 OFFSET 0;

-- Page 2: Next 10 results
SELECT * FROM users LIMIT 10 OFFSET 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ORDER BY Clause in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;ORDER BY&lt;/code&gt; clause is used to &lt;strong&gt;sort the result-set&lt;/strong&gt; of a query by one or more columns.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column1, column2, ...
FROM table_name
ORDER BY column1 [ASC|DESC];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;ASC → Ascending order (default)&lt;/li&gt;
&lt;li&gt;DESC → Descending order&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example: Sorting Users by Age (Ascending)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users
ORDER BY age;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Sorts users by age in ascending order (youngest first).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Example: Sorting by Age (Descending)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users
ORDER BY age DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns users sorted from oldest to youngest.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Aggregate Functions in SQL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Aggregate functions&lt;/strong&gt; perform a calculation on a set of values and return a single value.&lt;br&gt;&lt;br&gt;
They are commonly used with the &lt;code&gt;GROUP BY&lt;/code&gt; clause and help summarize data.&lt;/p&gt;


&lt;h4&gt;
  
  
  Common Aggregate Functions
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example Usage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;COUNT()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Counts the number of rows&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;COUNT(*)&lt;/code&gt;, &lt;code&gt;COUNT(column_name)&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SUM()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns the total sum&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SUM(price)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AVG()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns the average value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;AVG(score)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MIN()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns the minimum value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;MIN(age)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MAX()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns the maximum value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;MAX(salary)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example Table: &lt;code&gt;orders&lt;/code&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;customer&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Charlie&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Examples
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Count Total Orders&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT COUNT(*) FROM orders;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns: 4&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Total Sales&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT SUM(amount) FROM orders;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns: 500&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  GROUP BY Clause in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;GROUP BY&lt;/code&gt; clause is used to &lt;strong&gt;group rows&lt;/strong&gt; that have the same values in specified columns, often combined with &lt;strong&gt;aggregate functions&lt;/strong&gt; like &lt;code&gt;COUNT()&lt;/code&gt;, &lt;code&gt;SUM()&lt;/code&gt;, &lt;code&gt;AVG()&lt;/code&gt;, etc.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column_name, AGGREGATE_FUNCTION(column_name)
FROM table_name
GROUP BY column_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;customer&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Charlie&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Example: Total Spent by Each Customer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT customer, SUM(amount) AS total_spent
FROM orders
GROUP BY customer;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;customer&lt;/th&gt;
&lt;th&gt;total_spent&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Charlie&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  HAVING Clause in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;HAVING&lt;/code&gt; clause is used to &lt;strong&gt;filter groups&lt;/strong&gt; after aggregation — similar to &lt;code&gt;WHERE&lt;/code&gt;, but works with &lt;code&gt;GROUP BY&lt;/code&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column_name, AGGREGATE_FUNCTION(column_name)
FROM table_name
GROUP BY column_name
HAVING condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  HAVING vs WHERE
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Clause&lt;/th&gt;
&lt;th&gt;Filters&lt;/th&gt;
&lt;th&gt;Used With Aggregates?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Before grouping&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;HAVING&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;After grouping&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;customer&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Charlie&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Example: Customers who Spent More Than 100
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT customer, SUM(amount) AS total_spent
FROM orders
GROUP BY customer
HAVING SUM(amount) &amp;gt; 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;customer&lt;/th&gt;
&lt;th&gt;total_spent&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  General Order of SQL Clauses
&lt;/h3&gt;

&lt;p&gt;When writing SQL queries, there’s a &lt;strong&gt;logical order&lt;/strong&gt; that SQL follows to execute the clauses — which may be different from the order we write them.&lt;/p&gt;




&lt;h4&gt;
  
  
  Logical Execution Order in SQL
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Order&lt;/th&gt;
&lt;th&gt;Clause&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;FROM&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Specifies the table(s) to retrieve data from&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;JOIN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Combines rows from multiple tables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;WHERE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Filters rows based on a condition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;GROUP BY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Groups rows for aggregation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;HAVING&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Filters aggregated data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SELECT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Specifies which columns to return&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DISTINCT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes duplicate rows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8️⃣&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ORDER BY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sorts the result set&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9️⃣&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;LIMIT&lt;/code&gt; / &lt;code&gt;OFFSET&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Limits number of rows returned&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Example Query
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT customer, SUM(amount) AS total_spent
FROM orders
WHERE status = 'completed'
GROUP BY customer
HAVING SUM(amount) &amp;gt; 100
ORDER BY total_spent DESC
LIMIT 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Real-Life Analogy
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Think of SQL as a pipeline:&lt;/li&gt;
&lt;li&gt;Start by picking your data source (FROM)&lt;/li&gt;
&lt;li&gt;Filter raw rows (WHERE)&lt;/li&gt;
&lt;li&gt;Group them if needed (GROUP BY)&lt;/li&gt;
&lt;li&gt;Filter the groups (HAVING)&lt;/li&gt;
&lt;li&gt;Choose what to show (SELECT)&lt;/li&gt;
&lt;li&gt;Sort it (ORDER BY)&lt;/li&gt;
&lt;li&gt;Limit it (LIMIT)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  UPDATE Statement in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;UPDATE&lt;/code&gt; statement is used to &lt;strong&gt;modify existing records&lt;/strong&gt; in a table.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Update a User's Email
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE users
SET email = 'newemail@example.com'
WHERE id = 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Updates the email of the user whose ID is 5.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;SET SQL_SAFE_UPDATES = 0;&lt;/code&gt; in MySQL
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is &lt;code&gt;SQL_SAFE_UPDATES&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;In MySQL, the &lt;strong&gt;&lt;code&gt;SQL_SAFE_UPDATES&lt;/code&gt;&lt;/strong&gt; mode prevents accidental updates or deletions by &lt;strong&gt;requiring a &lt;code&gt;WHERE&lt;/code&gt; clause&lt;/strong&gt; or a &lt;strong&gt;&lt;code&gt;LIMIT&lt;/code&gt;&lt;/strong&gt; clause in &lt;code&gt;UPDATE&lt;/code&gt; and &lt;code&gt;DELETE&lt;/code&gt; statements.&lt;/p&gt;




&lt;h4&gt;
  
  
  Safe Updates Mode Enabled (&lt;code&gt;= 1&lt;/code&gt;)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SET SQL_SAFE_UPDATES = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  DELETE Statement in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;DELETE&lt;/code&gt; statement is used to &lt;strong&gt;remove rows&lt;/strong&gt; from a table.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE FROM table_name
WHERE condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Delete a Specific User
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE FROM users
WHERE id = 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Removes the user with id = 3 from the users table.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  ALTER TABLE in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;ALTER TABLE&lt;/code&gt; statement is used to &lt;strong&gt;modify the structure&lt;/strong&gt; of an existing table — including adding, deleting, or modifying columns.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE table_name
action;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add a Column
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE users
ADD phone_number VARCHAR(15);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Drop (Remove) a Column
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE users
DROP COLUMN phone_number;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Rename a Column (MySQL)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE users
CHANGE COLUMN old_name new_name datatype;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Example:
ALTER TABLE users
CHANGE COLUMN fullname full_name VARCHAR(100);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Modify Column Data Type
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE users
MODIFY COLUMN age SMALLINT;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Changes the age column's data type.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Rename Table
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RENAME TABLE old_table_name TO new_table_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Example:
RENAME TABLE customers TO clients;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add Constraints (e.g., NOT NULL)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE users
MODIFY COLUMN email VARCHAR(255) NOT NULL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  TRUNCATE TABLE in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;TRUNCATE TABLE&lt;/code&gt; statement is used to &lt;strong&gt;remove all rows&lt;/strong&gt; from a table &lt;strong&gt;very quickly&lt;/strong&gt; — while keeping the table structure intact.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUNCATE TABLE table_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUNCATE TABLE users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Deletes all rows from the users table, but does not remove the table itself.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  SQL Practice Section
&lt;/h3&gt;

&lt;p&gt;Boost your SQL skills by solving the following practice exercises using a sample &lt;code&gt;users&lt;/code&gt; and &lt;code&gt;orders&lt;/code&gt; table.&lt;/p&gt;




&lt;h4&gt;
  
  
  Sample Tables
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;users&lt;/code&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;age&lt;/th&gt;
&lt;th&gt;country&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;Canada&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;35&lt;/td&gt;
&lt;td&gt;USA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Charlie&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;Canada&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Diana&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;UK&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;orders&lt;/code&gt;
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;product&lt;/th&gt;
&lt;th&gt;amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Laptop&lt;/td&gt;
&lt;td&gt;1200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Headphones&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Monitor&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Mouse&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Beginner Practice
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Select all columns from the &lt;code&gt;users&lt;/code&gt; table.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Select names of users who are over 25.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM users
WHERE age &amp;gt; 25;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Find all orders with amount &amp;gt; 100.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM orders
WHERE amount &amp;gt; 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;ORDER BY&lt;/code&gt; to sort users by age in descending order.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users
ORDER BY age DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Intermediate Practice
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Count how many users are from Canada.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT COUNT(*) AS canada_users
FROM users
WHERE country = 'Canada';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Get the total amount spent by each user.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT user_id, SUM(amount) AS total_spent
FROM orders
GROUP BY user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Find the average age of all users.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT AVG(age) AS avg_age
FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;List users who haven't placed an order. &lt;em&gt;(Hint: LEFT JOIN)&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT u.*
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE o.id IS NULL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Advanced Practice
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Write a query to display the highest order amount for each user.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT user_id, MAX(amount) AS max_order
FROM orders
GROUP BY user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Update Bob’s age to 36.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE users
SET age = 36
WHERE name = 'Bob';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Delete users from the UK.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE FROM users
WHERE country = 'UK';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Truncate the &lt;code&gt;orders&lt;/code&gt; table.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUNCATE TABLE orders;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Practice makes perfect. Try solving these using a SQL playground or your local database setup.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  SQL JOINS
&lt;/h3&gt;

&lt;p&gt;In relational databases, &lt;strong&gt;JOINS&lt;/strong&gt; are used to combine rows from two or more tables based on a related column between them.&lt;/p&gt;




&lt;h4&gt;
  
  
  Sample Tables
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;users&lt;/code&gt; Table
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Carol&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;orders&lt;/code&gt; Table
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;product&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Laptop&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Monitor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Mouse&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  INNER JOIN
&lt;/h4&gt;

&lt;p&gt;Returns &lt;strong&gt;only matching rows&lt;/strong&gt; from both tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT users.name, orders.product
FROM users
INNER JOIN orders ON users.id = orders.user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  LEFT JOIN
&lt;/h4&gt;

&lt;p&gt;Returns all rows from the left table and matching rows from the right table. Fills in NULL where there's no match.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT users.name, orders.product
FROM users
LEFT JOIN orders ON users.id = orders.user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  RIGHT JOIN
&lt;/h4&gt;

&lt;p&gt;Returns all rows from the right table and matching rows from the left table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT users.name, orders.product
FROM users
RIGHT JOIN orders ON users.id = orders.user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  FULL OUTER JOIN
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Returns all rows from both tables, filling in NULL where there's no match.&lt;/li&gt;
&lt;li&gt;Not supported in MySQL directly — use UNION.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT users.name, orders.product
FROM users
LEFT JOIN orders ON users.id = orders.user_id
UNION
SELECT users.name, orders.product
FROM users
RIGHT JOIN orders ON users.id = orders.user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  SELF JOIN
&lt;/h4&gt;

&lt;p&gt;Joins a table to itself. Useful for hierarchical data (e.g., employees &amp;amp; managers).&lt;/p&gt;

&lt;p&gt;Example: Employees with Managers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT a.name AS employee, b.name AS manager
FROM employees a
JOIN employees b ON a.manager_id = b.id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  When to use each join
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Use Case Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;INNER JOIN&lt;/td&gt;
&lt;td&gt;Get orders made by users&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LEFT JOIN&lt;/td&gt;
&lt;td&gt;Show all users, even if they didn’t order&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RIGHT JOIN&lt;/td&gt;
&lt;td&gt;Show all orders, even without known users&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FULL JOIN&lt;/td&gt;
&lt;td&gt;Get complete list of users and orders&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SELF JOIN&lt;/td&gt;
&lt;td&gt;Compare rows in the same table (e.g., hierarchy)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  SQL Subqueries
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;subquery&lt;/strong&gt; (also known as an &lt;em&gt;inner query&lt;/em&gt; or &lt;em&gt;nested query&lt;/em&gt;) is a query &lt;strong&gt;inside another query&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can use subqueries in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;SELECT&lt;/code&gt; clause&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;FROM&lt;/code&gt; clause&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;WHERE&lt;/code&gt; clause&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Subquery in SELECT
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name,
  (SELECT COUNT(*) FROM orders WHERE orders.user_id = users.id) AS total_orders
FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Subquery in WHERE
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM users
WHERE id IN (
  SELECT user_id FROM orders WHERE product = 'Laptop'
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns users who bought a Laptop.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Subquery in FROM
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT avg_orders.user_id, avg_orders.avg_amount
FROM (
  SELECT user_id, AVG(amount) AS avg_amount
  FROM orders
  GROUP BY user_id
) AS avg_orders
WHERE avg_orders.avg_amount &amp;gt; 100;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Gets users whose average order amount is greater than 100.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;SubQuery vs Join&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;JOIN&lt;/th&gt;
&lt;th&gt;Subquery&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Speed&lt;/td&gt;
&lt;td&gt;Often faster with large data&lt;/td&gt;
&lt;td&gt;Slower for deeply nested logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Readability&lt;/td&gt;
&lt;td&gt;More intuitive for relations&lt;/td&gt;
&lt;td&gt;Better for calculated/aggregated fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Flexibility&lt;/td&gt;
&lt;td&gt;Less flexible in nested logic&lt;/td&gt;
&lt;td&gt;Powerful filtering, calculations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Views in SQL
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;View&lt;/strong&gt; is a &lt;strong&gt;virtual table&lt;/strong&gt; based on the result of a &lt;code&gt;SELECT&lt;/code&gt; query. It doesn't store data itself — it displays data from other tables.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use Views?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Simplify complex queries&lt;/li&gt;
&lt;li&gt;Enhance security (restrict access to certain columns)&lt;/li&gt;
&lt;li&gt;Present data in a customized format&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Create a View
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE VIEW user_orders AS
SELECT users.name, orders.product
FROM users
JOIN orders ON users.id = orders.user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Query a View
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM user_orders;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Indexes in SQL
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;Index&lt;/strong&gt; is like a book’s table of contents — it helps the database &lt;strong&gt;find rows faster&lt;/strong&gt; without scanning the entire table.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use Indexes?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;🔍 Speeds up &lt;code&gt;SELECT&lt;/code&gt; queries using &lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;JOIN&lt;/code&gt;, &lt;code&gt;ORDER BY&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;⚠️ Slightly slows down &lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt;, and &lt;code&gt;DELETE&lt;/code&gt; (due to index maintenance)&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Create an Index
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE INDEX idx_user_name
ON users(name);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Use it just like a regular table.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Using Indexes Automatically
&lt;/h4&gt;

&lt;p&gt;Once created, the database engine decides when to use the index. You don’t have to change your SQL queries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users WHERE name = 'Alice';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If name is indexed, this runs faster!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tip&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Index columns used in WHERE&lt;/td&gt;
&lt;td&gt;Faster lookups&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avoid over-indexing&lt;/td&gt;
&lt;td&gt;Wastes memory + slows writes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use composite indexes wisely&lt;/td&gt;
&lt;td&gt;Order matters (leftmost prefix)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Don’t index frequently updated columns&lt;/td&gt;
&lt;td&gt;Poor performance&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Transactions in SQL
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Transaction&lt;/strong&gt; is a sequence of operations performed as a &lt;strong&gt;single logical unit of work&lt;/strong&gt;. Either &lt;strong&gt;all operations succeed&lt;/strong&gt;, or &lt;strong&gt;none take effect&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use Transactions?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Maintain &lt;strong&gt;data integrity&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Useful for &lt;strong&gt;banking&lt;/strong&gt;, &lt;strong&gt;inventory&lt;/strong&gt;, &lt;strong&gt;batch updates&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Prevents partial updates if something goes wrong&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  ACID Properties
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Property&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A — Atomicity&lt;/td&gt;
&lt;td&gt;All or nothing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C — Consistency&lt;/td&gt;
&lt;td&gt;DB remains valid before/after&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;I — Isolation&lt;/td&gt;
&lt;td&gt;No interference from others&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;D — Durability&lt;/td&gt;
&lt;td&gt;Changes survive failures&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Transaction Syntax (MySQL)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;START TRANSACTION;

UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;COMMIT saves changes to the database.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Rollback a Transaction
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;START TRANSACTION;

UPDATE accounts SET balance = balance - 100 WHERE id = 1;

-- Simulate error
ROLLBACK;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;ROLLBACK undoes everything in the transaction block.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Autocommit Mode
&lt;/h4&gt;

&lt;p&gt;In MySQL, autocommit is ON by default, meaning every query is treated as its own transaction.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disable it manually if needed:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SET autocommit = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Banking systems&lt;/li&gt;
&lt;li&gt;E-commerce orders&lt;/li&gt;
&lt;li&gt;Stock updates&lt;/li&gt;
&lt;li&gt;Any multi-step update where failure in one step should undo all&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  CASE Statement in SQL
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;CASE&lt;/code&gt; statement allows you to add &lt;strong&gt;conditional logic&lt;/strong&gt; inside SQL queries — similar to &lt;code&gt;if...else&lt;/code&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name,
  CASE
    WHEN age &amp;lt; 18 THEN 'Minor'
    WHEN age BETWEEN 18 AND 60 THEN 'Adult'
    ELSE 'Senior'
  END AS age_group
FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example with SELECT
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name, country,
  CASE country
    WHEN 'Canada' THEN 'CA'
    WHEN 'United States' THEN 'US'
    ELSE 'Other'
  END AS country_code
FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Transforms country names into short codes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  UNION vs UNION ALL in SQL
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;UNION&lt;/code&gt; and &lt;code&gt;UNION ALL&lt;/code&gt; are used to &lt;strong&gt;combine the results&lt;/strong&gt; of two or more &lt;code&gt;SELECT&lt;/code&gt; queries into a single result set.&lt;/p&gt;




&lt;h4&gt;
  
  
  UNION
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Removes &lt;strong&gt;duplicate rows&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Sorts results by default&lt;/li&gt;
&lt;li&gt;Slower than &lt;code&gt;UNION ALL&lt;/code&gt; (because of deduplication)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM customers
UNION
SELECT name FROM vendors;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns a combined list of unique names from both tables.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  UNION ALL
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Keeps all rows (including duplicates)&lt;/li&gt;
&lt;li&gt;Faster (no deduplication)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM customers
UNION ALL
SELECT name FROM vendors;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Returns all names, including duplicates.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  EXISTS vs IN in SQL
&lt;/h3&gt;

&lt;p&gt;Both &lt;code&gt;EXISTS&lt;/code&gt; and &lt;code&gt;IN&lt;/code&gt; are used in &lt;code&gt;WHERE&lt;/code&gt; clauses to filter data based on &lt;strong&gt;subquery results&lt;/strong&gt;, but they work differently under the hood.&lt;/p&gt;




&lt;h4&gt;
  
  
  IN — Check if a value is in a list
&lt;/h4&gt;

&lt;p&gt;SELECT name FROM users&lt;br&gt;
WHERE id IN (&lt;br&gt;
  SELECT user_id FROM orders&lt;br&gt;
);&lt;/p&gt;
&lt;h4&gt;
  
  
  EXISTS — Checks if a row exists (faster with large datasets)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM users u
WHERE EXISTS (
  SELECT 1 FROM orders o
  WHERE o.user_id = u.id
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;Returns users where at least one matching order exists.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  Difference
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;IN&lt;/th&gt;
&lt;th&gt;EXISTS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Works with&lt;/td&gt;
&lt;td&gt;List of values&lt;/td&gt;
&lt;td&gt;Subquery with correlated condition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Slower with large result sets&lt;/td&gt;
&lt;td&gt;Faster with large, indexed tables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Subquery evaluated&lt;/td&gt;
&lt;td&gt;First (gets full list)&lt;/td&gt;
&lt;td&gt;Row-by-row (stops on first match)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can return NULLs&lt;/td&gt;
&lt;td&gt;May fail if subquery has NULLs&lt;/td&gt;
&lt;td&gt;Works fine&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Caution: NULL behavior
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM users
WHERE id IN (NULL); -- ❌ No results (not even NULL match)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM users
WHERE EXISTS (SELECT 1); -- ✅ Always true if subquery returns a row
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Common Table Expressions (CTEs) in SQL
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;CTE&lt;/strong&gt; (Common Table Expression) is a &lt;strong&gt;temporary named result set&lt;/strong&gt; that you can reference within a &lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt;, or &lt;code&gt;DELETE&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;Defined using the &lt;code&gt;WITH&lt;/code&gt; keyword.&lt;/p&gt;


&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WITH temp_table AS (
  SELECT user_id, COUNT(*) AS order_count
  FROM orders
  GROUP BY user_id
)
SELECT users.name, temp_table.order_count
FROM users
JOIN temp_table ON users.id = temp_table.user_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;The CTE temp_table holds aggregated order data for each user.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  Why Use CTEs?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Improves readability&lt;/li&gt;
&lt;li&gt;Reuses logic without repeating subqueries&lt;/li&gt;
&lt;li&gt;Helps break complex queries into parts&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Recursive CTE Example (Advanced)
&lt;/h4&gt;

&lt;p&gt;Use recursion to query hierarchical data (e.g., employees &amp;amp; managers):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WITH RECURSIVE employee_hierarchy AS (
  SELECT id, name, manager_id
  FROM employees
  WHERE manager_id IS NULL

  UNION ALL

  SELECT e.id, e.name, e.manager_id
  FROM employees e
  JOIN employee_hierarchy eh ON e.manager_id = eh.id
)
SELECT * FROM employee_hierarchy;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Builds a tree-like structure of employees reporting to managers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;CTE vs SubQuery&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;CTE&lt;/th&gt;
&lt;th&gt;Subquery&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Readability&lt;/td&gt;
&lt;td&gt;✅ High&lt;/td&gt;
&lt;td&gt;❌ Can get messy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reuse&lt;/td&gt;
&lt;td&gt;✅ Yes (name it once)&lt;/td&gt;
&lt;td&gt;❌ No reuse&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Recursion&lt;/td&gt;
&lt;td&gt;✅ Supports recursive queries&lt;/td&gt;
&lt;td&gt;❌ Not supported&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  🎉 Guide Complete!
&lt;/h4&gt;

&lt;p&gt;You've made it to the end of this comprehensive SQL guide — great job! 🚀&lt;/p&gt;

&lt;p&gt;Whether you're just starting out or brushing up your skills, remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🧠 &lt;em&gt;Practice is the key to mastery.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Apply what you've learned by solving real-world problems, building projects, or exploring sample databases.&lt;/p&gt;




&lt;p&gt;✅ &lt;strong&gt;Next Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Revisit tricky topics&lt;/li&gt;
&lt;li&gt;Solve all practice exercises&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;💬 Have questions or want more content like this?&lt;br&gt;&lt;br&gt;
Leave a comment or follow&lt;/p&gt;

&lt;p&gt;Stay consistent, keep practicing, and happy querying! 🧑‍💻&lt;/p&gt;

</description>
      <category>sql</category>
      <category>programming</category>
      <category>database</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Web Dev Day 8: Backend - NodeJS, Express, Ejs, REST (Part - 1)</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Tue, 03 Jun 2025 00:41:28 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/backend-nodejs-express-ejs-rest-part-1-53o0</link>
      <guid>https://dev.to/_bhupeshk_/backend-nodejs-express-ejs-rest-part-1-53o0</guid>
      <description>&lt;h3&gt;
  
  
  What is Node.js?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt; is a &lt;strong&gt;runtime environment&lt;/strong&gt; that allows you to run JavaScript &lt;strong&gt;outside of the browser&lt;/strong&gt; — on the &lt;strong&gt;server-side&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Simple Definition
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt; lets you use JavaScript to build &lt;strong&gt;server-side applications&lt;/strong&gt;, command-line tools, and backend services.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s built on &lt;strong&gt;Google Chrome’s V8 JavaScript engine&lt;/strong&gt;, which makes it &lt;strong&gt;fast, efficient, and lightweight&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  2. Key Features of Node.js
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🧠 JavaScript Runtime&lt;/td&gt;
&lt;td&gt;Runs JS outside the browser&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚡ Non-blocking I/O&lt;/td&gt;
&lt;td&gt;Handles many requests without waiting (asynchronous)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧵 Single-threaded&lt;/td&gt;
&lt;td&gt;Uses event loop &amp;amp; callbacks for concurrency&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📦 npm&lt;/td&gt;
&lt;td&gt;Built-in package manager with 2M+ packages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;💡 Cross-platform&lt;/td&gt;
&lt;td&gt;Works on Windows, macOS, Linux&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  3. What Can You Build with Node.js?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Web servers and APIs (REST, GraphQL)&lt;/li&gt;
&lt;li&gt;Real-time apps (chat, live dashboards)&lt;/li&gt;
&lt;li&gt;Command-line tools (CLI utilities)&lt;/li&gt;
&lt;li&gt;Microservices&lt;/li&gt;
&lt;li&gt;Backend logic for web/mobile apps&lt;/li&gt;
&lt;li&gt;File system and automation scripts&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  4. Basic Node.js Code Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// hello.js
console.log("Hello from Node.js!");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node hello.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello from Node.js!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Node.js vs Browser JavaScript
&lt;/h4&gt;

&lt;p&gt;Feature Browser JS  Node.js&lt;br&gt;
Environment Web browser Server, terminal, backend&lt;br&gt;
Access to DOM   ✅ Yes ❌ No&lt;br&gt;
File system access  ❌ No  ✅ Yes&lt;br&gt;
Modules ES modules or script tags   CommonJS (require), ES modules&lt;br&gt;
Purpose UI &amp;amp; frontend behavior  Backend, APIs, CLI tools&lt;/p&gt;
&lt;h4&gt;
  
  
  6. What is npm?
&lt;/h4&gt;

&lt;p&gt;npm = Node Package Manager&lt;br&gt;
It comes with Node.js and lets you install libraries and frameworks.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This installs Express.js, a popular web framework for Node.&lt;/p&gt;

&lt;h4&gt;
  
  
  7. Why Use Node.js?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript everywhere (frontend + backend)&lt;/li&gt;
&lt;li&gt;Fast performance (V8 engine)&lt;/li&gt;
&lt;li&gt;Scalable with event-driven model&lt;/li&gt;
&lt;li&gt;Great for building APIs and real-time apps&lt;/li&gt;
&lt;li&gt;Huge ecosystem with npm packages&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Node.js REPL – Read Eval Print Loop
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;REPL&lt;/strong&gt; stands for &lt;strong&gt;Read-Eval-Print Loop&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It’s an interactive environment that comes with Node.js where you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Type JavaScript code&lt;/li&gt;
&lt;li&gt;Execute it immediately&lt;/li&gt;
&lt;li&gt;See the result instantly&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  1. What is REPL?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;REPL is like a &lt;strong&gt;JavaScript playground&lt;/strong&gt; in your terminal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It allows you to &lt;strong&gt;experiment with code&lt;/strong&gt;, test logic, and explore Node.js features in real time.&lt;/p&gt;


&lt;h4&gt;
  
  
  2. How to Start the Node REPL
&lt;/h4&gt;

&lt;p&gt;Open your terminal and type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Working with Files in Node.js
&lt;/h3&gt;

&lt;p&gt;Node.js provides the built-in &lt;strong&gt;&lt;code&gt;fs&lt;/code&gt; (File System)&lt;/strong&gt; module to let you &lt;strong&gt;read, write, update, and delete files&lt;/strong&gt; directly from your code.&lt;/p&gt;

&lt;h3&gt;
  
  
  The &lt;code&gt;process&lt;/code&gt; Object in Node.js
&lt;/h3&gt;

&lt;p&gt;In Node.js, the global &lt;code&gt;process&lt;/code&gt; object provides &lt;strong&gt;information and control&lt;/strong&gt; over the &lt;strong&gt;current Node.js process&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What is &lt;code&gt;process&lt;/code&gt;?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;process&lt;/code&gt; object is a &lt;strong&gt;built-in global object&lt;/strong&gt; in Node.js.&lt;br&gt;&lt;br&gt;
It provides methods and properties to &lt;strong&gt;interact with the system&lt;/strong&gt;, &lt;strong&gt;handle input/output&lt;/strong&gt;, and &lt;strong&gt;control execution flow&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  2. Accessing Command Line Arguments
&lt;/h4&gt;

&lt;p&gt;console.log(process.argv);&lt;/p&gt;

&lt;p&gt;process.argv is an array containing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Node executable path&lt;/li&gt;
&lt;li&gt;The script file path&lt;/li&gt;
&lt;li&gt;Any additional arguments&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node app.js hello world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  '/usr/bin/node',
  '/path/to/app.js',
  'hello',
  'world'
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can access them like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const args = process.argv.slice(2);
console.log("User input:", args);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Exporting in Node.js Files
&lt;/h3&gt;

&lt;p&gt;In Node.js, &lt;strong&gt;modular programming&lt;/strong&gt; is achieved using the &lt;strong&gt;CommonJS module system&lt;/strong&gt;, which allows you to &lt;strong&gt;export and import code&lt;/strong&gt; between files.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Why Use &lt;code&gt;exports&lt;/code&gt;?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Organize code into &lt;strong&gt;smaller reusable files&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Share &lt;strong&gt;functions, variables, classes, or objects&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Keep your codebase &lt;strong&gt;clean and maintainable&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2. Basic Export with &lt;code&gt;module.exports&lt;/code&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;math.js&lt;/code&gt; (export file)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b) {
  return a + b;
}

function subtract(a, b) {
  return a - b;
}

module.exports = {
  add,
  subtract
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;app.js (import file)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const math = require('./math');

console.log(math.add(5, 3));       // 8
console.log(math.subtract(10, 4)); // 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Exporting from Directories in Node.js
&lt;/h3&gt;

&lt;p&gt;In Node.js, when you &lt;strong&gt;organize code across multiple files inside a folder&lt;/strong&gt;, you can simplify importing by &lt;strong&gt;exporting from the directory itself&lt;/strong&gt; using an &lt;code&gt;index.js&lt;/code&gt; file.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Why Export from a Directory?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Group related modules (e.g., &lt;code&gt;User&lt;/code&gt;, &lt;code&gt;Auth&lt;/code&gt;, &lt;code&gt;Utils&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Avoid long import paths&lt;/li&gt;
&lt;li&gt;Simplify the import statement with a single entry point&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2. Directory Structure Example
&lt;/h4&gt;

&lt;p&gt;/utils&lt;br&gt;
├── add.js&lt;br&gt;
├── subtract.js&lt;br&gt;
└── index.js&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;add.js&lt;/code&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b) {
  return a + b;
}

module.exports = add;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;subtract.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function subtract(a, b) {
  return a - b;
}

module.exports = subtract;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;index.js (in /utils folder)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const add = require('./add');
const subtract = require('./subtract');

module.exports = {
  add,
  subtract
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Importing from the Directory
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const utils = require('./utils');

console.log(utils.add(5, 3));       // 8
console.log(utils.subtract(10, 4)); // 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Node will automatically look for index.js when you require('./folder').&lt;/p&gt;

&lt;h3&gt;
  
  
  What is npm?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;npm&lt;/strong&gt; stands for &lt;strong&gt;Node Package Manager&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It is the &lt;strong&gt;default package manager for Node.js&lt;/strong&gt;, used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install libraries and tools&lt;/li&gt;
&lt;li&gt;Manage dependencies&lt;/li&gt;
&lt;li&gt;Publish your own packages&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  1. Key Facts About npm
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🧠 Name&lt;/td&gt;
&lt;td&gt;Node Package Manager&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📂 Comes With&lt;/td&gt;
&lt;td&gt;Node.js installation (&lt;code&gt;node -v&lt;/code&gt;, &lt;code&gt;npm -v&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🌍 Registry&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.npmjs.com" rel="noopener noreferrer"&gt;https://www.npmjs.com&lt;/a&gt; (over 2 million packages)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📦 File Used&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;package.json&lt;/code&gt; to manage project dependencies&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📥 Install Packages&lt;/td&gt;
&lt;td&gt;&lt;code&gt;npm install &amp;lt;package-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📤 Publish Package&lt;/td&gt;
&lt;td&gt;&lt;code&gt;npm publish&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  2. Installing a Package
&lt;/h4&gt;

&lt;p&gt;In Node.js, you can install external libraries (packages) using &lt;strong&gt;npm (Node Package Manager)&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install &amp;lt;package-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Adds it to the node_modules folder.&lt;/li&gt;
&lt;li&gt;Adds it to dependencies in package.json (if --save or default).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Understanding &lt;code&gt;package.json&lt;/code&gt; in Node.js
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;package.json&lt;/code&gt; file is the &lt;strong&gt;heart of any Node.js project&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It stores metadata about the project and manages its &lt;strong&gt;dependencies&lt;/strong&gt;, &lt;strong&gt;scripts&lt;/strong&gt;, and &lt;strong&gt;configuration&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Why &lt;code&gt;package.json&lt;/code&gt; Matters
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;📂 Describes your project (name, version, author, license)&lt;/li&gt;
&lt;li&gt;📦 Tracks installed packages (dependencies &amp;amp; devDependencies)&lt;/li&gt;
&lt;li&gt;⚙️ Defines scripts for tasks (start, test, build)&lt;/li&gt;
&lt;li&gt;🧩 Required to publish a package to npm&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  2. How to Create &lt;code&gt;package.json&lt;/code&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  3. Example package.json
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "my-app",
  "version": "1.0.0",
  "description": "A sample Node.js project",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "test": "echo \"No tests yet\""
  },
  "author": "Bhupesh Kumar",
  "license": "MIT",
  "dependencies": {
    "express": "^4.18.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.22"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Local vs Global Installation in npm
&lt;/h3&gt;

&lt;p&gt;When installing packages with &lt;code&gt;npm&lt;/code&gt;, you can choose between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local Installation&lt;/strong&gt;: For a specific project&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global Installation&lt;/strong&gt;: Available system-wide (all projects)&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  Local Installation
&lt;/h4&gt;
&lt;h4&gt;
  
  
  Command:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install &amp;lt;package-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Where It Goes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installed inside the project’s node_modules/ folder&lt;/li&gt;
&lt;li&gt;Listed in package.json under "dependencies" or "devDependencies"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use When:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The package is only needed for a specific project&lt;/li&gt;
&lt;li&gt;You want different versions in different projects&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Global Installation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Command:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g &amp;lt;package-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Where It Goes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installed in a system-wide folder&lt;/li&gt;
&lt;li&gt;Can be run from any terminal, any directory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use When:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Package is a command-line tool (e.g., nodemon, http-server, eslint)&lt;/li&gt;
&lt;li&gt;You want it available globally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Checking Install Type&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List global packages:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm list -g --depth=0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;List local project packages:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm list --depth=0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Importing Modules in Node.js
&lt;/h3&gt;

&lt;p&gt;Node.js follows a &lt;strong&gt;modular architecture&lt;/strong&gt;, where you can &lt;strong&gt;import and reuse code&lt;/strong&gt; across files using the &lt;code&gt;require()&lt;/code&gt; function or the modern &lt;code&gt;import&lt;/code&gt; statement (ES Modules).&lt;/p&gt;




&lt;h4&gt;
  
  
  1. CommonJS Syntax (&lt;code&gt;require&lt;/code&gt;)
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Importing a File:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const math = require('./math');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. ES Module Syntax (import)
&lt;/h4&gt;

&lt;p&gt;Use this syntax when "type": "module" is set in package.json.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Import Default Export:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Import Named Export:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { add, subtract } from './math.js';

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Import Everything:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as utils from './utils.js';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is Express.js?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Express.js&lt;/strong&gt; is a &lt;strong&gt;minimal and flexible Node.js web application framework&lt;/strong&gt; that provides a robust set of features for building &lt;strong&gt;web applications&lt;/strong&gt; and &lt;strong&gt;APIs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It simplifies the process of handling routes, requests, middleware, and server logic in Node.js.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Why Use Express?
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Benefit&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🧩 Middleware support&lt;/td&gt;
&lt;td&gt;Add custom functionality easily&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📦 Routing system&lt;/td&gt;
&lt;td&gt;Handle URL endpoints with clean syntax&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚙️ Simplified server setup&lt;/td&gt;
&lt;td&gt;No need to write verbose Node.js HTTP code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🌐 REST API building&lt;/td&gt;
&lt;td&gt;Perfect for backend APIs and microservices&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🛠 Integrations&lt;/td&gt;
&lt;td&gt;Easily integrates with MongoDB, MySQL, templating engines&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  2. Installing Express
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Basic Express Server
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();

// Route
app.get('/', (req, res) =&amp;gt; {
  res.send('Hello from Express!');
});

// Start server
app.listen(3000, () =&amp;gt; {
  console.log('🚀 Server running on http://localhost:3000');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Library vs Framework in JavaScript
&lt;/h3&gt;

&lt;p&gt;Understanding the difference between a &lt;strong&gt;library&lt;/strong&gt; and a &lt;strong&gt;framework&lt;/strong&gt; is essential for every developer. They both help you write better code, but they do so in different ways.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Definition
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;📚 Library&lt;/td&gt;
&lt;td&gt;A &lt;strong&gt;collection of reusable functions&lt;/strong&gt; or modules that you call as needed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🏗 Framework&lt;/td&gt;
&lt;td&gt;A &lt;strong&gt;structured platform&lt;/strong&gt; that dictates the architecture and flow of your app.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  2. Control Flow: &lt;strong&gt;Inversion of Control&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is the &lt;strong&gt;main difference&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Framework&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Who’s in charge?&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;You&lt;/strong&gt; call the library code&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Framework&lt;/strong&gt; calls your code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Control Flow&lt;/td&gt;
&lt;td&gt;You remain in control&lt;/td&gt;
&lt;td&gt;Framework is in control&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  3. Examples
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lodash&lt;/td&gt;
&lt;td&gt;Utility functions for arrays, objects, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Axios&lt;/td&gt;
&lt;td&gt;HTTP request library&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;jQuery&lt;/td&gt;
&lt;td&gt;DOM manipulation library&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Framework&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Express.js&lt;/td&gt;
&lt;td&gt;Web framework for Node.js&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular&lt;/td&gt;
&lt;td&gt;Full-fledged frontend framework&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Next.js&lt;/td&gt;
&lt;td&gt;Framework for React apps&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  4. Real-life Analogy
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;library&lt;/strong&gt; is like ordering à la carte at a restaurant — you choose what you want and when.&lt;br&gt;&lt;br&gt;
A &lt;strong&gt;framework&lt;/strong&gt; is like a fixed menu — it decides the courses and when you get them.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  5. Summary Table
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Framework&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Control&lt;/td&gt;
&lt;td&gt;You call the code&lt;/td&gt;
&lt;td&gt;It calls your code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Flexibility&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Less, follows set structure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Learning curve&lt;/td&gt;
&lt;td&gt;Generally lower&lt;/td&gt;
&lt;td&gt;Can be higher&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Examples&lt;/td&gt;
&lt;td&gt;Lodash, Axios, jQuery&lt;/td&gt;
&lt;td&gt;Express, Angular, Next.js&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Final Thoughts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use a &lt;strong&gt;library&lt;/strong&gt; when you need specific functionality without strict rules.&lt;/li&gt;
&lt;li&gt;Use a &lt;strong&gt;framework&lt;/strong&gt; when you need a complete structure and guidelines for building your app.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;✨ &lt;em&gt;“Libraries are helpers. Frameworks are architects.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Handling Requests in Express.js
&lt;/h3&gt;

&lt;p&gt;Express.js makes it easy to handle different types of HTTP requests (&lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;, etc.) using intuitive routing methods.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Basic Structure of a Route
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.METHOD(PATH, HANDLER)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sending a Response in Express.js
&lt;/h3&gt;

&lt;p&gt;In Express.js, you use the &lt;code&gt;res&lt;/code&gt; (response) object to send data back to the client.&lt;br&gt;&lt;br&gt;
This response could be text, HTML, JSON, status codes, or redirects.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. &lt;code&gt;res.send()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Sends a plain text or HTML response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/', (req, res) =&amp;gt; {
  res.send('Hello from Express!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Routing in Express.js
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Routing&lt;/strong&gt; in Express refers to how an application responds to client requests for a particular endpoint (URI + HTTP method).&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Basic Route Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.METHOD(PATH, HANDLER)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;METHOD: HTTP verb like GET, POST, etc.&lt;/li&gt;
&lt;li&gt;PATH: Route path&lt;/li&gt;
&lt;li&gt;HANDLER: Callback function (req, res)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Example Routes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/', (req, res) =&amp;gt; {
  res.send('Home Page');
});

app.post('/submit', (req, res) =&amp;gt; {
  res.send('Form Submitted');
});

app.put('/update', (req, res) =&amp;gt; {
  res.send('Update Successful');
});

app.delete('/delete', (req, res) =&amp;gt; {
  res.send('Deleted Successfully');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Route Parameters
&lt;/h4&gt;

&lt;p&gt;Used to capture values from the URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/users/:id', (req, res) =&amp;gt; {
  res.send(`User ID: ${req.params.id}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Query Parameters
&lt;/h4&gt;

&lt;p&gt;Used to pass optional key-value pairs in the URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/search', (req, res) =&amp;gt; {
  res.send(`You searched for: ${req.query.q}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;URL Example: /search?q=express&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Multiple Handlers
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/demo',
  (req, res, next) =&amp;gt; {
    console.log('Middleware 1');
    next();
  },
  (req, res) =&amp;gt; {
    res.send('Final Response');
  }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Installing and Using Nodemon in Node.js
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Nodemon&lt;/strong&gt; is a utility that automatically restarts your Node.js application whenever file changes are detected. It boosts productivity during development.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What is Nodemon?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Monitors your project files.&lt;/li&gt;
&lt;li&gt;Automatically restarts the server on save.&lt;/li&gt;
&lt;li&gt;Ideal for development (not used in production).&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2. Installing Nodemon
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Local Installation (recommended)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Path Parameters in Express.js
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Path parameters&lt;/strong&gt; (also called &lt;strong&gt;route parameters&lt;/strong&gt;) allow you to capture dynamic values from the URL path and use them inside your route handler.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What are Path Parameters?
&lt;/h4&gt;

&lt;p&gt;Path parameters are defined using a &lt;strong&gt;colon (&lt;code&gt;:&lt;/code&gt;)&lt;/strong&gt; followed by a name in the route path.&lt;/p&gt;

&lt;p&gt;They are useful for handling &lt;strong&gt;dynamic URLs&lt;/strong&gt;, such as &lt;code&gt;/users/123&lt;/code&gt; or &lt;code&gt;/products/456&lt;/code&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  2. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/users/:id', (req, res) =&amp;gt; {
  const userId = req.params.id;
  res.send(`User ID is: ${userId}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Query Strings in Express.js
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Query strings&lt;/strong&gt; are key-value pairs added to the end of a URL to send optional parameters to the server.&lt;/p&gt;

&lt;p&gt;They appear after a &lt;code&gt;?&lt;/code&gt; and are separated by &lt;code&gt;&amp;amp;&lt;/code&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What is a Query String?
&lt;/h4&gt;

&lt;p&gt;URL Example: &lt;a href="http://localhost:3000/search?term=express&amp;amp;limit=10" rel="noopener noreferrer"&gt;http://localhost:3000/search?term=express&amp;amp;limit=10&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;term&lt;/code&gt; = &lt;code&gt;express&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;limit&lt;/code&gt; = &lt;code&gt;10&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2. Accessing Query Strings in Express
&lt;/h4&gt;

&lt;p&gt;Use the &lt;code&gt;req.query&lt;/code&gt; object to access query string parameters.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/search', (req, res) =&amp;gt; {
  const { term, limit } = req.query;
  res.send(`Search Term: ${term}, Limit: ${limit}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If user visits:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://localhost:3000/search?term=express&amp;amp;limit=5" rel="noopener noreferrer"&gt;http://localhost:3000/search?term=express&amp;amp;limit=5&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Search Term: express, Limit: 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Templating in Express.js
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Templating&lt;/strong&gt; allows you to generate dynamic HTML pages in Express by embedding server-side data into frontend code using template engines.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What is a Template Engine?
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;template engine&lt;/strong&gt; enables you to render dynamic content on the server before sending it to the client.&lt;/p&gt;

&lt;p&gt;Popular engines include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;EJS&lt;/strong&gt; (Embedded JavaScript)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pug&lt;/strong&gt; (formerly Jade)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handlebars&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2. Installing a Template Engine (Example: EJS)
&lt;/h4&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;EJS (Embedded JavaScript Templates)&lt;/strong&gt; is a simple templating language that lets you generate HTML markup with plain JavaScript.
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install ejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Setting Up EJS with Express
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();

// Set EJS as the template engine
app.set('view engine', 'ejs');

// Optional: set views folder
app.set('views', './views');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Creating a View File
&lt;/h4&gt;

&lt;p&gt;Create a file: views/home.ejs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;&amp;lt;%= title %&amp;gt;&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;h1&amp;gt;Hello, &amp;lt;%= user %&amp;gt;!&amp;lt;/h1&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Rendering the View
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/', (req, res) =&amp;gt; {
  res.render('home', {
    title: 'Welcome Page',
    user: 'Bhupesh'
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output HTML sent to browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello, Bhupesh!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Views Directory in Express.js
&lt;/h3&gt;

&lt;p&gt;In Express.js, the &lt;strong&gt;views directory&lt;/strong&gt; is where your template (view) files are stored when using a templating engine like &lt;strong&gt;EJS&lt;/strong&gt;, &lt;strong&gt;Pug&lt;/strong&gt;, or &lt;strong&gt;Handlebars&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Default Views Directory
&lt;/h4&gt;

&lt;p&gt;By default, Express looks for views in a folder named &lt;code&gt;views&lt;/code&gt; in the &lt;strong&gt;project root&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Customizing the Views Directory
&lt;/h4&gt;

&lt;p&gt;You can change the default views folder using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.set('views', './templates');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Interpolation Syntax in EJS
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Interpolation&lt;/strong&gt; in EJS (Embedded JavaScript) allows you to embed dynamic data into your HTML templates. This makes it easy to render server-side data directly in your views.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Basic Interpolation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello, &amp;lt;%= name %&amp;gt;!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&amp;lt;%= %&amp;gt; outputs the value of a variable with HTML escaping.&lt;/li&gt;
&lt;li&gt;Useful for injecting safe, dynamic content.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;res.render('home', { name: 'Bhupesh' });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rendered HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello, Bhupesh!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;%= %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Output with HTML escaping&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;%- %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Output without escaping (raw HTML)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;% %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;JavaScript logic (no output)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Passing Data to EJS Templates in Express.js
&lt;/h3&gt;

&lt;p&gt;When using &lt;strong&gt;EJS&lt;/strong&gt; as your view engine, you can easily pass data from your &lt;strong&gt;Express routes&lt;/strong&gt; to the EJS template for dynamic rendering.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;

&lt;p&gt;res.render('templateName', dataObject);&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Example
&lt;/h4&gt;

&lt;p&gt;Route (Express)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/', (req, res) =&amp;gt; {
  res.render('home', { username: 'Bhupesh', loggedIn: true });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Template (views/home.ejs)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Welcome, &amp;lt;%= username %&amp;gt;!&amp;lt;/h1&amp;gt;

&amp;lt;% if (loggedIn) { %&amp;gt;
  &amp;lt;p&amp;gt;You are logged in.&amp;lt;/p&amp;gt;
&amp;lt;% } else { %&amp;gt;
  &amp;lt;p&amp;gt;Please log in to continue.&amp;lt;/p&amp;gt;
&amp;lt;% } %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output in browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Welcome, Bhupesh!
You are logged in.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Syntax/Usage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;&lt;code&gt;res.render('view', { key: value })&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Access in EJS&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;%= key %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arrays/Objects&lt;/td&gt;
&lt;td&gt;Loop through with &lt;code&gt;&amp;lt;% %&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Conditional Logic&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;% if (...) { %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Conditional Statements in EJS
&lt;/h3&gt;

&lt;p&gt;EJS (Embedded JavaScript) allows you to write JavaScript logic directly in your HTML templates using special tags.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Basic &lt;code&gt;if&lt;/code&gt; Statement
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;% if (user) { %&amp;gt;
  &amp;lt;h2&amp;gt;Welcome, &amp;lt;%= user %&amp;gt;!&amp;lt;/h2&amp;gt;
&amp;lt;% } %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;% if () { %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Run JavaScript conditionally&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;% } else { %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Alternative block&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;%= %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Output escaped value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;%- %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Output unescaped (raw HTML) value&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Loops in EJS
&lt;/h3&gt;

&lt;p&gt;EJS allows you to use JavaScript loops to dynamically render lists, tables, and repeated elements in your HTML.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. &lt;code&gt;forEach&lt;/code&gt; Loop
&lt;/h4&gt;

&lt;p&gt;Commonly used to iterate over arrays in EJS templates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul&amp;gt;
  &amp;lt;% items.forEach(item =&amp;gt; { %&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;%= item %&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;% }) %&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Classic for Loop&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can use a standard JavaScript for loop too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul&amp;gt;
  &amp;lt;% for(let i = 0; i &amp;lt; items.length; i++) { %&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;%= items[i] %&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;% } %&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Syntax Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;forEach&lt;/code&gt; loop&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;% items.forEach(item =&amp;gt; { %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Classic &lt;code&gt;for&lt;/code&gt; loop&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;% for (let i = 0; i &amp;lt; n; i++) { %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Output value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;%= item %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JS logic only&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;% %&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Serving Static Files in EJS with Express
&lt;/h3&gt;

&lt;p&gt;To use &lt;strong&gt;images, CSS, JS&lt;/strong&gt;, or other static assets in your EJS templates, Express provides a built-in way to serve static files using &lt;code&gt;express.static()&lt;/code&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Set Up the Static Directory
&lt;/h4&gt;

&lt;p&gt;Create a folder named &lt;code&gt;public&lt;/code&gt; (or any name you prefer):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project/
├── public/
│ ├── css/
│ │ └── style.css
│ ├── js/
│ │ └── script.js
│ └── images/
│ └── logo.png
├── views/
│ └── home.ejs
├── index.js
└── package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✅ 2. Serve Static Files with Express
&lt;/h2&gt;

&lt;p&gt;In your &lt;code&gt;index.js&lt;/code&gt; or &lt;code&gt;app.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();

// Serve static files from the "public" directory
app.use(express.static('public'));

app.set('view engine', 'ejs');
app.set('views', './views');

app.get('/', (req, res) =&amp;gt; {
  res.render('home');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Use Static Files in EJS
&lt;/h4&gt;

&lt;p&gt;Linking a CSS File&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- views/home.ejs --&amp;gt;
&amp;lt;link rel="stylesheet" href="/css/style.css"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding a JS File&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="/js/script.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using an Image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="/images/logo.png" alt="Logo"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  EJS Includes
&lt;/h3&gt;

&lt;p&gt;EJS supports file inclusion using the &lt;code&gt;&amp;lt;%- include() %&amp;gt;&lt;/code&gt; syntax. This allows you to &lt;strong&gt;reuse common components&lt;/strong&gt; like headers, footers, navbars, etc., across multiple pages.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%- include('filename') %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Example Folder Structure
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project/
├── views/
│   ├── partials/
│   │   ├── header.ejs
│   │   └── footer.ejs
│   ├── pages/
│   │   └── home.ejs
│   └── layout.ejs
├── index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using Partials in a Page
&lt;/h4&gt;

&lt;p&gt;pages/home.ejs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%- include('../partials/header') %&amp;gt;

&amp;lt;h2&amp;gt;Welcome to the Home Page&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;This is dynamic content for the homepage.&amp;lt;/p&amp;gt;

&amp;lt;%- include('../partials/footer') %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  GET and POST Requests in Express.js
&lt;/h3&gt;

&lt;p&gt;Express.js supports different types of HTTP requests, with &lt;strong&gt;GET&lt;/strong&gt; and &lt;strong&gt;POST&lt;/strong&gt; being the most commonly used.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. GET Request
&lt;/h4&gt;

&lt;p&gt;Used to &lt;strong&gt;retrieve data&lt;/strong&gt; from the server. Typically triggered by clicking a link or visiting a URL.&lt;/p&gt;

&lt;h4&gt;
  
  
  Route Definition:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/greet', (req, res) =&amp;gt; {
  res.send('Hello from GET!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access Query Parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// URL: /search?term=express
app.get('/search', (req, res) =&amp;gt; {
  const { term } = req.query;
  res.send(`You searched for: ${term}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. POST Request
&lt;/h4&gt;

&lt;p&gt;Used to send data to the server, often from forms.&lt;/p&gt;

&lt;p&gt;You must use express.urlencoded() middleware to parse form data.&lt;/p&gt;

&lt;p&gt;Enable Form Data Parsing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(express.urlencoded({ extended: true }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Route Definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/submit', (req, res) =&amp;gt; {
  const { name } = req.body;
  res.send(`Form submitted by ${name}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTML Form Example (EJS):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form action="/submit" method="POST"&amp;gt;
  &amp;lt;input type="text" name="name" placeholder="Enter your name" /&amp;gt;
  &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Handling POST Requests in Express.js
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;POST request&lt;/strong&gt; is used to &lt;strong&gt;send data&lt;/strong&gt; from the client to the server. It is commonly used in form submissions and APIs.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Enabling Body Parsing
&lt;/h4&gt;

&lt;p&gt;To read form data or JSON from &lt;code&gt;req.body&lt;/code&gt;, use the following middlewares:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();

// Middleware to parse URL-encoded form data
app.use(express.urlencoded({ extended: true }));

// Middleware to parse JSON data
app.use(express.json());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Basic POST Route
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/submit', (req, res) =&amp;gt; {
  const { name, email } = req.body;
  res.send(`Received: ${name}, ${email}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Example Form (HTML or EJS)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form action="/submit" method="POST"&amp;gt;
  &amp;lt;input type="text" name="name" placeholder="Enter your name" /&amp;gt;
  &amp;lt;input type="email" name="email" placeholder="Enter your email" /&amp;gt;
  &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is REST?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;REST&lt;/strong&gt; stands for &lt;strong&gt;Representational State Transfer&lt;/strong&gt;. It is a &lt;strong&gt;software architectural style&lt;/strong&gt; used to design scalable, stateless, and cacheable &lt;strong&gt;web services&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Key Concepts of REST:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Client-Server Architecture&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Separation of concerns: client (frontend) handles UI, server (backend) handles data and logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Stateless&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each request from the client contains all the information needed to process the request.&lt;/li&gt;
&lt;li&gt;The server &lt;strong&gt;does not remember&lt;/strong&gt; any client context between requests.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cacheable&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Responses must explicitly indicate if they are cacheable or not to improve performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Uniform Interface&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A consistent way of interacting with resources using standard HTTP methods:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;GET&lt;/code&gt;: Retrieve data&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;POST&lt;/code&gt;: Create data&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PUT&lt;/code&gt;: Update data&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DELETE&lt;/code&gt;: Remove data&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Layered System&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Architecture composed of hierarchical layers, allowing load balancers, security layers, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Resource-Based&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Everything is considered a resource (e.g., users, posts, products).&lt;/li&gt;
&lt;li&gt;Resources are identified using &lt;strong&gt;URIs&lt;/strong&gt; (Uniform Resource Identifiers).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h4&gt;
  
  
  Example of RESTful API:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;GET /users → Get all users&lt;/li&gt;
&lt;li&gt;GET /users/5 → Get user with ID 5&lt;/li&gt;
&lt;li&gt;POST /users → Create a new user&lt;/li&gt;
&lt;li&gt;PUT /users/5 → Update user with ID 5&lt;/li&gt;
&lt;li&gt;DELETE /users/5 → Delete user with ID 5&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  REST vs RESTful
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;REST&lt;/strong&gt; is the architectural style.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RESTful&lt;/strong&gt; APIs are web services that follow the REST principles.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Summary
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Term&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;REST&lt;/td&gt;
&lt;td&gt;Design principle for APIs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stateless&lt;/td&gt;
&lt;td&gt;No session data stored on server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Resource&lt;/td&gt;
&lt;td&gt;Data like users, posts, etc. accessed via URI&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HTTP Methods&lt;/td&gt;
&lt;td&gt;GET, POST, PUT, DELETE, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  CRUD Operations in Web Development
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;CRUD&lt;/strong&gt; stands for the four basic types of operations you can perform on persistent data in most applications:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;C&lt;/strong&gt;reate | &lt;strong&gt;R&lt;/strong&gt;ead | &lt;strong&gt;U&lt;/strong&gt;pdate | &lt;strong&gt;D&lt;/strong&gt;elete&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These operations are the foundation of working with databases, APIs, and RESTful services.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Create (POST)
&lt;/h4&gt;

&lt;p&gt;Used to &lt;strong&gt;add new data&lt;/strong&gt; to a database or resource.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example (REST API):
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;POST /users&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Sample Request Body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "Bhupesh",
  "email": "bhupesh@example.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Read (GET)
&lt;/h4&gt;

&lt;p&gt;Used to retrieve data from the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /users          // Get all users
GET /users/123      // Get user with ID 123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Update (PUT / PATCH)
&lt;/h4&gt;

&lt;p&gt;Used to modify existing data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PUT: Replaces the entire resource&lt;/li&gt;
&lt;li&gt;PATCH: Updates part of the resource&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;PUT /users/123&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Sample Request Body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "Bhupesh Kumar",
  "email": "bhupesh@example.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Delete (DELETE)
&lt;/h4&gt;

&lt;p&gt;Used to remove data from the server.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DELETE /users/123&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating RESTful APIs with Express.js
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;RESTful API&lt;/strong&gt; uses HTTP methods to perform CRUD operations on resources. Express.js makes it easy to build these APIs in Node.js.&lt;/p&gt;




&lt;h4&gt;
  
  
  Step 1: Setup
&lt;/h4&gt;

&lt;h4&gt;
  
  
  1. Initialize Project
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
npm install express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Create app.js
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();
const PORT = 3000;

app.use(express.json()); // Middleware to parse JSON

app.listen(PORT, () =&amp;gt; {
  console.log(`Server is running on port ${PORT}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Define In-Memory Data
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let users = [
  { id: 1, name: "Alice" },
  { id: 2, name: "Bhupesh" }
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Create RESTful Routes
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. GET All Users&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/users', (req, res) =&amp;gt; {
  res.json(users);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. GET User by ID&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/users/:id', (req, res) =&amp;gt; {
  const user = users.find(u =&amp;gt; u.id === parseInt(req.params.id));
  user ? res.json(user) : res.status(404).send("User not found");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. POST Create New User&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/users', (req, res) =&amp;gt; {
  const newUser = {
    id: users.length + 1,
    name: req.body.name
  };
  users.push(newUser);
  res.status(201).json(newUser);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. PUT Update User&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.put('/users/:id', (req, res) =&amp;gt; {
  const user = users.find(u =&amp;gt; u.id === parseInt(req.params.id));
  if (user) {
    user.name = req.body.name;
    res.json(user);
  } else {
    res.status(404).send("User not found");
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. DELETE User&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.delete('/users/:id', (req, res) =&amp;gt; {
  users = users.filter(u =&amp;gt; u.id !== parseInt(req.params.id));
  res.send("User deleted");
});

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Index Route in RESTful APIs
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is an Index Route?
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;index route&lt;/strong&gt; is the endpoint that returns a &lt;strong&gt;list of all resources&lt;/strong&gt; of a particular type.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It usually responds to a &lt;strong&gt;GET request&lt;/strong&gt; at the root of a resource path.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Create and New Routes in RESTful APIs
&lt;/h3&gt;

&lt;p&gt;In a RESTful API, "Create" and "New" routes are used to add new resources to a collection.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. New Route
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;New route&lt;/strong&gt; is used to &lt;strong&gt;display a form&lt;/strong&gt; (typically in server-rendered apps) to collect data for creating a new resource.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🚫 Not commonly used in API-only backends — more relevant for apps using templating engines like EJS or Pug.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Route Pattern:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;GET /users/new&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Redirects in Express.js
&lt;/h3&gt;

&lt;p&gt;In Express.js, the &lt;code&gt;res.redirect()&lt;/code&gt; method is used to &lt;strong&gt;redirect the client to a different URL&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;res.redirect([statusCode], path)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/', (req, res) =&amp;gt; {
  res.send('Welcome to the homepage!');
});

app.get('/home', (req, res) =&amp;gt; {
  res.redirect('/');  // Redirect to homepage
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Show Route in RESTful APIs
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Show Route&lt;/strong&gt; is used to &lt;strong&gt;retrieve and display a single resource&lt;/strong&gt; based on its unique identifier (usually an &lt;code&gt;id&lt;/code&gt;).&lt;/p&gt;




&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Fetch details of a specific item&lt;/li&gt;
&lt;li&gt;Common in detail views (e.g., user profile, blog post, product page)&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  URL Pattern
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;GET /resources/:id&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/users/:id', (req, res) =&amp;gt; {
  const userId = parseInt(req.params.id);
  const user = users.find(u =&amp;gt; u.id === userId);

  if (user) {
    res.json(user);
  } else {
    res.status(404).send("User not found");
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating Unique IDs for Posts using UUID in Express.js
&lt;/h3&gt;

&lt;p&gt;To uniquely identify each post or record in your API, you can use &lt;strong&gt;UUIDs (Universally Unique Identifiers)&lt;/strong&gt; instead of simple numeric IDs.&lt;/p&gt;




&lt;h4&gt;
  
  
  Why Use UUID?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Universally unique across systems&lt;/li&gt;
&lt;li&gt;Safer than incremental IDs&lt;/li&gt;
&lt;li&gt;Great for distributed applications&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Step 1: Install UUID Library
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install uuid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Import and Use UUID
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const { v4: uuidv4 } = require('uuid');

const app = express();
app.use(express.json());

let posts = [];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Create a Post with UUID
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/posts', (req, res) =&amp;gt; {
  const newPost = {
    id: uuidv4(),
    title: req.body.title,
    content: req.body.content
  };

  posts.push(newPost);
  res.status(201).json(newPost);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4: Show a Post by UUID
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/posts/:id', (req, res) =&amp;gt; {
  const post = posts.find(p =&amp;gt; p.id === req.params.id);
  if (post) {
    res.json(post);
  } else {
    res.status(404).json({ message: "Post not found" });
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example Output
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": "a12f4a1b-9f34-432a-b23d-8dfd0fe7a239",
  "title": "My First Post",
  "content": "This is my first post using UUID!"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Update Route in RESTful APIs
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Update Route&lt;/strong&gt; allows you to &lt;strong&gt;modify an existing resource&lt;/strong&gt;. It uses either the &lt;code&gt;PUT&lt;/code&gt; or &lt;code&gt;PATCH&lt;/code&gt; HTTP method.&lt;/p&gt;




&lt;h4&gt;
  
  
  When to Use PUT vs PATCH
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PUT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replaces the entire resource&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PATCH&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Updates part of the resource (partial)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  URL Pattern
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PUT /posts/:id
PATCH /posts/:id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example in Express.js
&lt;/h4&gt;

&lt;p&gt;Assume we are working with an array of posts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let posts = [
  { id: "1", title: "Old Title", content: "Old content" }
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  PUT Example (Full Update)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.put('/posts/:id', (req, res) =&amp;gt; {
  const post = posts.find(p =&amp;gt; p.id === req.params.id);
  if (post) {
    post.title = req.body.title;
    post.content = req.body.content;
    res.json(post);
  } else {
    res.status(404).json({ message: "Post not found" });
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  PATCH Example (Partial Update)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.patch('/posts/:id', (req, res) =&amp;gt; {
  const post = posts.find(p =&amp;gt; p.id === req.params.id);
  if (post) {
    if (req.body.title) post.title = req.body.title;
    if (req.body.content) post.content = req.body.content;
    res.json(post);
  } else {
    res.status(404).json({ message: "Post not found" });
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample Request Body (for PUT)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "title": "Updated Title",
  "content": "Updated content goes here"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Edit Route in RESTful APIs
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Edit Route&lt;/strong&gt; is typically used in &lt;strong&gt;server-rendered applications&lt;/strong&gt; (like those using EJS or Pug) to &lt;strong&gt;display a form pre-filled with existing data&lt;/strong&gt;, allowing a user to make changes to a resource.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ Note: This is different from the &lt;strong&gt;Update Route&lt;/strong&gt;, which actually performs the data update.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Render a form to &lt;strong&gt;edit&lt;/strong&gt; a resource (like a post or user)&lt;/li&gt;
&lt;li&gt;Pre-populate form fields with current data&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  URL Pattern
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;GET /posts/:id/edit&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example in Express.js with EJS
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/posts/:id/edit', (req, res) =&amp;gt; {
  const post = posts.find(p =&amp;gt; p.id === req.params.id);
  if (post) {
    res.render('editPost', { post });
  } else {
    res.status(404).send("Post not found");
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Sample EJS Template (editPost.ejs)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Edit Post&amp;lt;/h1&amp;gt;
&amp;lt;form action="/posts/&amp;lt;%= post.id %&amp;gt;?_method=PUT" method="POST"&amp;gt;
  &amp;lt;input type="text" name="title" value="&amp;lt;%= post.title %&amp;gt;" required /&amp;gt;
  &amp;lt;textarea name="content"&amp;gt;&amp;lt;%= post.content %&amp;gt;&amp;lt;/textarea&amp;gt;
  &amp;lt;button type="submit"&amp;gt;Update&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Make sure to use middleware like method-override to support PUT/DELETE via forms.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Destroy Route in RESTful APIs
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Destroy Route&lt;/strong&gt; allows you to &lt;strong&gt;delete a specific resource&lt;/strong&gt; from the server/database. It uses the &lt;code&gt;DELETE&lt;/code&gt; HTTP method.&lt;/p&gt;




&lt;h4&gt;
  
  
  Purpose
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Permanently remove an item (e.g., post, user, product)&lt;/li&gt;
&lt;li&gt;Triggered by user action (e.g., clicking a delete button)&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  URL Pattern
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;DELETE /posts/:id&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example in Express.js
&lt;/h4&gt;

&lt;p&gt;Assume an in-memory posts array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let posts = [
  { id: "1", title: "Post 1" },
  { id: "2", title: "Post 2" }
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Destroy Route
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.delete('/posts/:id', (req, res) =&amp;gt; {
  const postId = req.params.id;
  const postIndex = posts.findIndex(p =&amp;gt; p.id === postId);

  if (postIndex !== -1) {
    posts.splice(postIndex, 1);
    res.send(`Post ${postId} deleted`);
  } else {
    res.status(404).send("Post not found");
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If using an HTML form to trigger this, you'll need method-override.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  That's a Wrap for Part 1!
&lt;/h3&gt;

&lt;p&gt;We’ve officially wrapped up &lt;strong&gt;Part 1&lt;/strong&gt; of our backend journey, covering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌐 Node.js fundamentals and REPL&lt;/li&gt;
&lt;li&gt;📦 npm, modules, and project structure&lt;/li&gt;
&lt;li&gt;🚀 Express.js for building web servers&lt;/li&gt;
&lt;li&gt;📄 EJS templating for dynamic content&lt;/li&gt;
&lt;li&gt;🛠️ RESTful routing (Index, Show, Create, Edit, Update, Destroy)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're building APIs or full-stack web apps, these core concepts are the foundation for becoming a strong backend developer.&lt;/p&gt;

&lt;p&gt;🧠 &lt;strong&gt;Tip:&lt;/strong&gt; Keep experimenting with small projects as you go. It’s the best way to learn!&lt;/p&gt;

&lt;p&gt;📢 Stay tuned for &lt;strong&gt;Part 2&lt;/strong&gt;, where we dive deeper into backend magic with databases, authentication, and more real-world features! 🔥&lt;/p&gt;

&lt;p&gt;💬 Got feedback or suggestions? Drop a comment and let’s grow together.&lt;/p&gt;

&lt;p&gt;🚀 Happy Coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>simonsays-js: A Fun Memory Game Built with JavaScript!</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Sun, 27 Apr 2025 21:51:10 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/simonsays-js-a-fun-memory-game-built-with-javascript-1e56</link>
      <guid>https://dev.to/_bhupeshk_/simonsays-js-a-fun-memory-game-built-with-javascript-1e56</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey everyone!&lt;/em&gt;&lt;/strong&gt;👋&lt;br&gt;&lt;br&gt;
I'm excited to share my latest project: &lt;strong&gt;Simon Says JS&lt;/strong&gt; — a colorful memory game built using &lt;strong&gt;pure HTML, CSS, and JavaScript&lt;/strong&gt;. 🎨🧠&lt;/p&gt;

&lt;p&gt;In this post, I'll walk you through the project overview, key features, and how you can try it out!&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Overview
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Simon Says&lt;/strong&gt; game is a classic memory challenge where you need to repeat an increasingly long sequence of colors correctly.&lt;br&gt;&lt;br&gt;
I built a modern, mobile-responsive version from scratch to sharpen my front-end skills like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DOM manipulation&lt;/li&gt;
&lt;li&gt;Event handling&lt;/li&gt;
&lt;li&gt;CSS animations&lt;/li&gt;
&lt;li&gt;Game logic building&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Live Demo:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;👉 &lt;a href="https://bhupeshk3014.github.io/simonsays-js/" rel="noopener noreferrer"&gt;Play Simon Says JS here!&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Source Code:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/bhupeshk3014/simonsays-js" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🛠️ Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🎨 Colorful animated buttons&lt;/li&gt;
&lt;li&gt;📈 Dynamic level progression&lt;/li&gt;
&lt;li&gt;🔊 Button click sounds and Game Over sounds&lt;/li&gt;
&lt;li&gt;🏆 High score tracking with LocalStorage&lt;/li&gt;
&lt;li&gt;📱 Fully mobile responsive&lt;/li&gt;
&lt;li&gt;✨ Smooth transitions and UI animations&lt;/li&gt;
&lt;li&gt;🖥️ Clean design with modern fonts and gradient backgrounds&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎮 How to Play
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Press the &lt;strong&gt;Start&lt;/strong&gt; button to begin the game.&lt;/li&gt;
&lt;li&gt;Watch carefully as the game flashes a random color.&lt;/li&gt;
&lt;li&gt;Click the colored buttons in the &lt;strong&gt;same sequence&lt;/strong&gt; shown.&lt;/li&gt;
&lt;li&gt;Each new level adds &lt;strong&gt;one more color&lt;/strong&gt; to the sequence.&lt;/li&gt;
&lt;li&gt;If you make a mistake, it's &lt;strong&gt;Game Over&lt;/strong&gt; — your score and High Score will be displayed.&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;Start&lt;/strong&gt; again to try and beat your &lt;strong&gt;High Score&lt;/strong&gt;! 🏆&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  📸 Sneak Peek (Screenshots)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Desktop View:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpllop4z1v9r02xe16ujf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpllop4z1v9r02xe16ujf.png" alt="Desktop View" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mobile View:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmo04ezj6niupx9uar4af.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmo04ezj6niupx9uar4af.png" alt="Mobile View" width="612" height="1332"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  📂 Tech Stack Used
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTML5&lt;/strong&gt; — for structure&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS3&lt;/strong&gt; — for styles, responsive layout, transitions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript (Vanilla)&lt;/strong&gt; — for game logic and user interaction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Fonts&lt;/strong&gt; — for modern typography&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LocalStorage API&lt;/strong&gt; — to save High Scores&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  ✨ Challenges and Learning Points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Handling real-time event listening for multiple buttons&lt;/li&gt;
&lt;li&gt;Managing sequence arrays and checking user input dynamically&lt;/li&gt;
&lt;li&gt;Adding smooth CSS transitions for better UX&lt;/li&gt;
&lt;li&gt;Working with LocalStorage to persist data across browser sessions&lt;/li&gt;
&lt;li&gt;Making the page fully responsive for mobile screens&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🚀 Future Improvements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🎮 Add difficulty levels (Easy, Medium, Hard)&lt;/li&gt;
&lt;li&gt;🔊 Add background music with mute/unmute button&lt;/li&gt;
&lt;li&gt;🏆 Create a leaderboard system&lt;/li&gt;
&lt;li&gt;📱 Make it a Progressive Web App (PWA) for offline play&lt;/li&gt;
&lt;li&gt;✨ Add new bonus game modes like "Reverse Simon"&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🙌 Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Building &lt;strong&gt;Simon Says JS&lt;/strong&gt; was a great way to practice and apply front-end skills, especially &lt;strong&gt;DOM manipulation and game logic&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
I'm really proud of how polished and mobile-friendly it turned out! &lt;/p&gt;

&lt;p&gt;I'd love your feedback and ideas for future upgrades! 🚀&lt;br&gt;&lt;br&gt;
If you like it, feel free to ⭐ the GitHub repo!&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🙏&lt;br&gt;&lt;br&gt;
🚀 &lt;strong&gt;Challenge your memory now:&lt;/strong&gt; &lt;a href="https://bhupeshk3014.github.io/simonsays-js/" rel="noopener noreferrer"&gt;Play Simon Says JS!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Web Dev Day 7: JavaScript Guide Part 2</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Thu, 06 Mar 2025 19:23:55 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/web-dev-day-7-javascript-guide-part-2-2neg</link>
      <guid>https://dev.to/_bhupeshk_/web-dev-day-7-javascript-guide-part-2-2neg</guid>
      <description>&lt;h3&gt;
  
  
  What is the DOM in JavaScript?
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Document Object Model (DOM)&lt;/strong&gt; is a &lt;strong&gt;programming interface&lt;/strong&gt; that allows JavaScript to &lt;strong&gt;interact with, manipulate, and update web pages dynamically&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;It represents an &lt;strong&gt;HTML document as a tree structure&lt;/strong&gt;, where each &lt;strong&gt;HTML element is a node&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Understanding the DOM Structure
&lt;/h4&gt;

&lt;p&gt;Consider this &lt;strong&gt;HTML document&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;DOM Example&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1 id="heading"&amp;gt;Hello, DOM!&amp;lt;/h1&amp;gt;
    &amp;lt;p class="text"&amp;gt;This is a paragraph.&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How the DOM Represents This Page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Document
 ├── html
 │    ├── head
 │    │    ├── title
 │    ├── body
 │         ├── h1 (id="heading")
 │         ├── p (class="text")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Accessing the DOM Using JavaScript
&lt;/h4&gt;

&lt;p&gt;Selecting Elements by ID (getElementById)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let heading = document.getElementById("heading");
console.log(heading.textContent);  
// Output: "Hello, DOM!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Selecting Elements by Class (getElementsByClassName&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let paragraphs = document.getElementsByClassName("text");
console.log(paragraphs[0].textContent);  
// Output: "This is a paragraph."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Selecting Elements by Tag Name (getElementsByTagName)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let allHeadings = document.getElementsByTagName("h1");
console.log(allHeadings[0].textContent);  
// Output: "Hello, DOM!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modern Way: Using querySelector and querySelectorAll&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let heading = document.querySelector("#heading"); // Selects by ID
let paragraph = document.querySelector(".text"); // Selects first element with class
let allParagraphs = document.querySelectorAll(".text"); // Selects all elements with class

console.log(heading.textContent);  
// Output: "Hello, DOM!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Modifying the DOM (Changing Content)
&lt;/h4&gt;

&lt;p&gt;Changing Inner HTML&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("heading").innerHTML = "&amp;lt;span style='color:red'&amp;gt;Hello, JS!&amp;lt;/span&amp;gt;";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing Text Content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("heading").textContent = "Hello, JavaScript!";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Manipulating DOM Elements
&lt;/h4&gt;

&lt;p&gt;Adding a New Element (createElement &amp;amp; appendChild)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let newPara = document.createElement("p");
newPara.textContent = "This is a new paragraph!";
document.body.appendChild(newPara);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Removing an Element (removeChild)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let element = document.getElementById("heading");
element.parentNode.removeChild(element);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing CSS Styles Using JavaScript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("heading").style.color = "blue";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Handling Events in the DOM
&lt;/h4&gt;

&lt;p&gt;Adding an Event Listener&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("heading").addEventListener("click", function() {
    alert("Heading clicked!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Removing an Event Listener&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet() {
    console.log("Heading clicked!");
}

let heading = document.getElementById("heading");
heading.addEventListener("click", greet);
heading.removeEventListener("click", greet);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Manipulating Attributes in JavaScript (DOM)
&lt;/h3&gt;

&lt;p&gt;JavaScript provides &lt;strong&gt;methods&lt;/strong&gt; to &lt;strong&gt;add, modify, and remove&lt;/strong&gt; attributes of HTML elements dynamically.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Accessing Attributes
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;getAttribute()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Gets the value of an attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let link = document.querySelector("a");
console.log(link.getAttribute("href"));  
// Output: The URL inside the `href` attribute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;setAttribute()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Sets or updates an attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let link = document.querySelector("a");
link.setAttribute("href", "https://example.com");
console.log(link.getAttribute("href"));  
// Output: "https://example.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;hasAttribute()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Checks if an element has a specific attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let button = document.querySelector("button");

if (button.hasAttribute("disabled")) {
    console.log("Button is disabled");
} else {
    console.log("Button is enabled");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;removeAttribute()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Removes an attribute from an element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let input = document.querySelector("input");
input.removeAttribute("disabled");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Working with class Attributes
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;classList.add()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Adds a class to an element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let box = document.querySelector(".box");
box.classList.add("active");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;classList.remove()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Removes a class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;box.classList.remove("active");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;classList.toggle()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Toggles a class on/off.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;box.classList.toggle("hidden");

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;classList.contains()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Checks if an element has a class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(box.classList.contains("hidden"));  
// Output: true or false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Working with data-* Attributes
&lt;/h4&gt;

&lt;p&gt;Custom attributes (data-*) store additional data in elements.&lt;/p&gt;

&lt;h4&gt;
  
  
  Getting data-* Attributes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let button = document.querySelector("button");
console.log(button.getAttribute("data-user-id"));  
// Output: User ID stored in `data-user-id`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using dataset for Easier Access
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(button.dataset.userId);  
// Output: User ID stored in `data-user-id`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting data-* Attributes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;button.dataset.status = "active";
console.log(button.dataset.status);  
// Output: "active"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Enabling/Disabling Elements (disabled Attribute)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let button = document.querySelector("button");

// Disable the button
button.setAttribute("disabled", true);

// Enable the button
button.removeAttribute("disabled");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Manipulating Styles in JavaScript (DOM)
&lt;/h3&gt;

&lt;p&gt;JavaScript allows you to &lt;strong&gt;dynamically change CSS styles&lt;/strong&gt; on HTML elements using the &lt;strong&gt;&lt;code&gt;style&lt;/code&gt; property&lt;/strong&gt; or &lt;strong&gt;CSS classes&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Changing Inline Styles
&lt;/h4&gt;

&lt;p&gt;You can modify &lt;strong&gt;CSS properties&lt;/strong&gt; using the &lt;code&gt;.style&lt;/code&gt; property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let box = document.querySelector(".box");
box.style.backgroundColor = "blue";
box.style.color = "white";
box.style.padding = "20px";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Modifying Multiple Styles Using cssText
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;box.style.cssText = "background: red; color: white; padding: 15px;";

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using classList for CSS Manipulation
&lt;/h4&gt;

&lt;p&gt;Instead of modifying styles directly, use CSS classes for better control.&lt;/p&gt;

&lt;h4&gt;
  
  
  Adding a Class
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;box.classList.add("highlight");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Removing a Class
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;box.classList.remove("highlight");

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Toggling a Class (On/Off)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;box.classList.toggle("hidden");

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Checking if an Element Has a Class
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(box.classList.contains("hidden"));  
// Output: true or false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Navigating the Page Using JavaScript (DOM Navigation)
&lt;/h3&gt;

&lt;p&gt;JavaScript provides various &lt;strong&gt;DOM navigation methods&lt;/strong&gt; to move between &lt;strong&gt;elements on a web page&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Accessing Parent, Child, and Sibling Elements
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Getting the &lt;strong&gt;Parent Element&lt;/strong&gt; (&lt;code&gt;parentNode&lt;/code&gt; &amp;amp; &lt;code&gt;parentElement&lt;/code&gt;)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let child = document.querySelector(".child");
console.log(child.parentNode);   
console.log(child.parentElement);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature                 Method
Get Parent Element  parentNode, parentElement
Get Child Elements  firstElementChild, lastElementChild
Get Sibling Elements    nextElementSibling, previousElementSibling
Scroll to Section   scrollIntoView()
Redirect to URL         window.location.href
Reload Page         window.location.reload()
Navigate History    window.history.back() / forward()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding Elements to a Page Using JavaScript (DOM Manipulation)
&lt;/h3&gt;

&lt;p&gt;JavaScript allows you to &lt;strong&gt;dynamically create and add elements&lt;/strong&gt; to the webpage using the &lt;strong&gt;DOM API&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Creating and Appending an Element
&lt;/h4&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;createElement()&lt;/code&gt; + &lt;code&gt;appendChild()&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let newPara = document.createElement("p"); // Create &amp;lt;p&amp;gt; element
newPara.textContent = "This is a new paragraph!"; // Add text

document.body.appendChild(newPara); // Append to body
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Adding an Element Inside a Specific Parent
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let parentDiv = document.getElementById("container");

let newDiv = document.createElement("div");
newDiv.textContent = "Hello, this is a new div!";
newDiv.classList.add("new-box");

parentDiv.appendChild(newDiv);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using insertBefore() (Insert at a Specific Position)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let list = document.getElementById("list");
let newItem = document.createElement("li");
newItem.textContent = "New Item";

let firstItem = list.firstElementChild; // Get first item
list.insertBefore(newItem, firstItem);  // Insert before it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature                        Method
Create an Element          createElement("tag")
Add Text                   element.textContent = "Text"
Append to End                  appendChild(element)
Insert Before                  insertBefore(newElement, referenceElement)
Insert at Specific Position    insertAdjacentHTML(position, html)
Prepend Element                prepend(element)
Clone Element                  cloneNode(true)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Removing Elements from a Page Using JavaScript (DOM Manipulation)
&lt;/h3&gt;

&lt;p&gt;JavaScript allows you to &lt;strong&gt;remove elements dynamically&lt;/strong&gt; from the DOM using various methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Removing an Element Using &lt;code&gt;remove()&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let element = document.getElementById("box");
element.remove();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Removing a Child Element Using removeChild()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let parent = document.getElementById("container");
let child = document.getElementById("child");

parent.removeChild(child);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature                       Method
Remove an element         element.remove()
Remove a child                parent.removeChild(child)
Remove first/last child       firstElementChild.remove() / lastElementChild.remove()
Remove all children       innerHTML = ""
Remove using parent       parentNode.removeChild(element)
Remove multiple elements      querySelectorAll().forEach(el =&amp;gt; el.remove())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  DOM Events in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;DOM Events&lt;/strong&gt; allow JavaScript to detect and respond to user interactions such as &lt;strong&gt;clicks, key presses, and mouse movements&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Adding an Event Listener (&lt;code&gt;addEventListener&lt;/code&gt;)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let button = document.getElementById("myButton");

button.addEventListener("click", function() {
    console.log("Button clicked!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;onclick&lt;/code&gt; and &lt;code&gt;onmouseenter&lt;/code&gt; Events in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript provides &lt;strong&gt;event handlers&lt;/strong&gt; like &lt;code&gt;onclick&lt;/code&gt; and &lt;code&gt;onmouseenter&lt;/code&gt; to &lt;strong&gt;detect user interactions&lt;/strong&gt; such as &lt;strong&gt;clicks and mouse movements&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. &lt;code&gt;onclick&lt;/code&gt; Event (Detects Clicks)
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;onclick&lt;/code&gt; event&lt;/strong&gt; fires when an element is &lt;strong&gt;clicked&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;onclick&lt;/code&gt; with HTML (Inline)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button onclick="alert('Button clicked!')"&amp;gt;Click Me&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using onclick in JavaScript (Better Approach)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let button = document.getElementById("myButton");

button.onclick = function() {
    alert("Button clicked!");
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using addEventListener("click") (Best Practice)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let btn = document.getElementById("myButton");

btn.addEventListener("click", () =&amp;gt; {
    alert("Button clicked using addEventListener!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. onmouseenter Event (Mouse Hover)
&lt;/h4&gt;

&lt;p&gt;The onmouseenter event fires when the mouse enters an element.&lt;/p&gt;

&lt;p&gt;Example: Changing Background Color on Hover&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let box = document.getElementById("box");

box.onmouseenter = function() {
    box.style.backgroundColor = "yellow";
};

box.onmouseleave = function() {
    box.style.backgroundColor = "white";
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;addEventListener()&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;addEventListener()&lt;/code&gt; method&lt;/strong&gt; allows JavaScript to &lt;strong&gt;attach event listeners&lt;/strong&gt; to HTML elements dynamically.&lt;br&gt;&lt;br&gt;
It is the &lt;strong&gt;preferred method&lt;/strong&gt; for handling events because it supports &lt;strong&gt;multiple handlers&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.addEventListener("event", function);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Event Listeners for Elements in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript &lt;strong&gt;event listeners&lt;/strong&gt; allow you to detect &lt;strong&gt;user interactions&lt;/strong&gt; on elements like &lt;strong&gt;buttons, links, inputs, and forms&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Adding an Event Listener (&lt;code&gt;addEventListener()&lt;/code&gt;)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.addEventListener("event", function);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;this&lt;/code&gt; in Event Listeners in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;this&lt;/code&gt; keyword&lt;/strong&gt; behaves differently in event listeners based on how the function is defined.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. &lt;code&gt;this&lt;/code&gt; in a Regular Function (Refers to the Element)
&lt;/h4&gt;

&lt;p&gt;When using a &lt;strong&gt;regular function&lt;/strong&gt;, &lt;code&gt;this&lt;/code&gt; refers to &lt;strong&gt;the element that triggered the event&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let button = document.getElementById("myButton");

button.addEventListener("click", function() {
    console.log(this);  // Logs the button element
    this.style.backgroundColor = "blue"; // Changes button color
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Keyboard Events in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript &lt;strong&gt;keyboard events&lt;/strong&gt; allow you to detect when a user presses or releases a key.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Types of Keyboard Events
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;keydown&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fires when a key is &lt;strong&gt;pressed down&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;keyup&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fires when a key is &lt;strong&gt;released&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;keypress&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;(Deprecated) Similar to &lt;code&gt;keydown&lt;/code&gt;, but does not detect &lt;code&gt;Shift&lt;/code&gt;, &lt;code&gt;Ctrl&lt;/code&gt;, &lt;code&gt;Alt&lt;/code&gt;, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Best Practice:&lt;/strong&gt; Use &lt;strong&gt;&lt;code&gt;keydown&lt;/code&gt; and &lt;code&gt;keyup&lt;/code&gt;&lt;/strong&gt; instead of &lt;code&gt;keypress&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Detecting Key Press (&lt;code&gt;keydown&lt;/code&gt;)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.addEventListener("keydown", (event) =&amp;gt; {
    console.log(`Key pressed: ${event.key}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Form Events in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript &lt;strong&gt;form events&lt;/strong&gt; allow you to detect user interactions with form elements, such as &lt;strong&gt;input fields, checkboxes, and buttons&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Common Form Events
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| Event | Description |
|-------|------------|
| `submit` | Fires when a form is submitted |
| `focus` | Fires when an input field gains focus |
| `blur` | Fires when an input field loses focus |
| `change` | Fires when an input value changes (for dropdowns, checkboxes, etc.) |
| `input` | Fires when the user types in an input field |
| `reset` | Fires when the form is reset |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Prevent Default Form Submission (&lt;code&gt;submit&lt;/code&gt; Event)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let form = document.getElementById("myForm");

form.addEventListener("submit", (event) =&amp;gt; {
    event.preventDefault(); // Prevent page reload
    console.log("Form submitted!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Extracting Form Data in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript allows you to &lt;strong&gt;retrieve form input values&lt;/strong&gt; dynamically for validation, processing, or sending data to a server.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Extracting Data Using &lt;code&gt;querySelector&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("myForm").addEventListener("submit", function(event) {
    event.preventDefault(); // Prevent page reload

    let name = document.querySelector("#name").value;
    let email = document.querySelector("#email").value;
    let message = document.querySelector("#message").value;

    console.log(`Name: ${name}, Email: ${email}, Message: ${message}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Extracting Data Using elements[]
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("myForm").addEventListener("submit", function(event) {
    event.preventDefault();

    let form = event.target;
    let name = form.elements["name"].value;
    let email = form.elements["email"].value;

    console.log(`Name: ${name}, Email: ${email}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Extracting Checkbox and Radio Button Values
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("myForm").addEventListener("submit", function(event) {
    event.preventDefault();

    let agree = document.querySelector("#agree").checked;
    let gender = document.querySelector('input[name="gender"]:checked').value;

    console.log(`Agreement: ${agree}, Gender: ${gender}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature                    Method
Get Input Value            document.querySelector("#id").value
Get Checkbox Value     document.querySelector("#id").checked
Get Selected Radio Value document.querySelector('input[name="name"]:checked').value
Get Dropdown Value     document.querySelector("#id").value
Extract All Form Data      new FormData(form).entries()
Send Data to Server    fetch("URL", { method: "POST", body: formData })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;change&lt;/code&gt; Event in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;change&lt;/code&gt; event&lt;/strong&gt; fires when a form input &lt;strong&gt;loses focus after a value change&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It is commonly used for &lt;strong&gt;dropdowns, checkboxes, radio buttons, and text inputs&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.addEventListener("change", function(event) {
    console.log(event.target.value);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;input&lt;/code&gt; Event in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;input&lt;/code&gt; event&lt;/strong&gt; fires &lt;strong&gt;whenever the value of an input field changes&lt;/strong&gt;, making it ideal for &lt;strong&gt;live updates&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.addEventListener("input", function(event) {
    console.log(event.target.value);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Event Bubbling in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Event bubbling&lt;/strong&gt; is a concept in the DOM where an event &lt;strong&gt;starts from the target element&lt;/strong&gt; and &lt;strong&gt;propagates upwards&lt;/strong&gt; to its ancestors.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. How Event Bubbling Works
&lt;/h4&gt;

&lt;p&gt;Consider the following HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="parent"&amp;gt;
    &amp;lt;button id="child"&amp;gt;Click Me&amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's add event listeners:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("child").addEventListener("click", () =&amp;gt; {
    console.log("Child clicked!");
});

document.getElementById("parent").addEventListener("click", () =&amp;gt; {
    console.log("Parent clicked!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clicking the button logs:&lt;/p&gt;

&lt;p&gt;Child clicked!&lt;br&gt;
Parent clicked!&lt;/p&gt;

&lt;p&gt;The event starts at the child (button) and bubbles up to the parent (div).&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Stopping Event Bubbling (stopPropagation())
&lt;/h4&gt;

&lt;p&gt;Use event.stopPropagation() to prevent bubbling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("child").addEventListener("click", (event) =&amp;gt; {
    event.stopPropagation();
    console.log("Child clicked!");
});

document.getElementById("parent").addEventListener("click", () =&amp;gt; {
    console.log("Parent clicked!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, clicking the button only logs:&lt;/p&gt;

&lt;p&gt;Child clicked!&lt;/p&gt;

&lt;p&gt;The parent event is NOT triggered.&lt;/p&gt;

&lt;h3&gt;
  
  
  Event Delegation in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Event Delegation&lt;/strong&gt; is a technique in JavaScript where a &lt;strong&gt;single event listener&lt;/strong&gt; is added to a parent element to handle events on multiple child elements, even if they are added dynamically.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Why Use Event Delegation?
&lt;/h4&gt;

&lt;h3&gt;
  
  
  🔹 Without Event Delegation (Adding Event Listeners to Each Button)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let buttons = document.querySelectorAll(".btn");

buttons.forEach(button =&amp;gt; {
    button.addEventListener("click", () =&amp;gt; {
        console.log("Button clicked!");
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Does not work for dynamically added elements.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Using Event Delegation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("parent").addEventListener("click", (event) =&amp;gt; {
    if (event.target.matches(".btn")) {
        console.log(`Button Clicked: ${event.target.textContent}`);
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why Use?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only one event listener is needed.&lt;/li&gt;
&lt;li&gt;Works for both existing and dynamically added elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  JavaScript Call Stack
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Call Stack&lt;/strong&gt; in JavaScript is a &lt;strong&gt;mechanism&lt;/strong&gt; that the JavaScript engine uses to &lt;strong&gt;keep track of function calls&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It follows the &lt;strong&gt;Last In, First Out (LIFO)&lt;/strong&gt; principle.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. What is the Call Stack?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When you &lt;strong&gt;invoke a function&lt;/strong&gt;, JavaScript &lt;strong&gt;adds it (pushes)&lt;/strong&gt; onto the stack.&lt;/li&gt;
&lt;li&gt;When the function &lt;strong&gt;returns&lt;/strong&gt;, JavaScript &lt;strong&gt;removes it (pops)&lt;/strong&gt; from the stack.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The most recent function&lt;/strong&gt; call is always at the &lt;strong&gt;top&lt;/strong&gt; of the stack.&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  2. How It Works
&lt;/h4&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet() {
    console.log("Hello");
}

function welcome() {
    greet();
    console.log("Welcome!");
}

welcome();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Visualizing the JavaScript Call Stack
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Basic Example
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet() {
    console.log("Hello!");
}

function welcome() {
    greet();
    console.log("Welcome!");
}

welcome();

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

&lt;/div&gt;

&lt;h4&gt;
  
  
  Call Stack Step-by-Step:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Initially:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(empty)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Call &lt;code&gt;welcome()&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| welcome |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inside &lt;code&gt;welcome()&lt;/code&gt;, call &lt;code&gt;greet()&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| greet |
| welcome |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;greet()&lt;/code&gt; logs "Hello" and finishes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| welcome |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;welcome()&lt;/code&gt; logs "Welcome!" and finishes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(empty)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Final Output in Console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello!
Welcome!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  2. Nested Function Calls Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function first() {
    console.log("First");
    second();
}

function second() {
    console.log("Second");
    third();
}

function third() {
    console.log("Third");
}

first();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Call Stack Timeline:
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Moment&lt;/th&gt;
&lt;th&gt;Call Stack&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Start&lt;/td&gt;
&lt;td&gt;(empty)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Call &lt;code&gt;first()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;first()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inside &lt;code&gt;first()&lt;/code&gt;, call &lt;code&gt;second()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;second()&lt;/code&gt; ➔ &lt;code&gt;first()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inside &lt;code&gt;second()&lt;/code&gt;, call &lt;code&gt;third()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;third()&lt;/code&gt; ➔ &lt;code&gt;second()&lt;/code&gt; ➔ &lt;code&gt;first()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;third()&lt;/code&gt; completes&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;second()&lt;/code&gt; ➔ &lt;code&gt;first()&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;second()&lt;/code&gt; completes&lt;/td&gt;
&lt;td&gt;&lt;code&gt;first()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;first()&lt;/code&gt; completes&lt;/td&gt;
&lt;td&gt;(empty)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Final Output in Console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First
Second
Third
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  3. Visual Representation (Graphical)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time ➡️
----------------------------------------------------

Step 1: Call first()

[ first ]

Step 2: first() calls second()

[ second ]
[ first ]

Step 3: second() calls third()

[ third ]
[ second ]
[ first ]

Step 4: third() finishes

[ second ]
[ first ]

Step 5: second() finishes

[ first ]

Step 6: first() finishes

(empty)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breakpoints in JavaScript (Debugging with DevTools)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Breakpoints&lt;/strong&gt; are a powerful feature that allows you to &lt;strong&gt;pause code execution&lt;/strong&gt; at a specific line, so you can &lt;strong&gt;inspect values, control flow, and debug issues&lt;/strong&gt; step-by-step.&lt;/p&gt;




&lt;h3&gt;
  
  
  JavaScript is Single-Threaded
&lt;/h3&gt;

&lt;p&gt;JavaScript is a &lt;strong&gt;single-threaded&lt;/strong&gt; programming language, meaning it &lt;strong&gt;can only execute one task at a time&lt;/strong&gt; in a single line of execution.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. What Does Single-Threaded Mean?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Only &lt;strong&gt;one command&lt;/strong&gt; is being processed at a time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One call stack&lt;/strong&gt; and &lt;strong&gt;one memory heap&lt;/strong&gt; are used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No two pieces of code&lt;/strong&gt; run simultaneously in the same thread.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Imagine a cashier at a store who can only serve &lt;strong&gt;one customer at a time&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The next customer must &lt;strong&gt;wait&lt;/strong&gt; until the current one is &lt;strong&gt;fully processed&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  2. How JavaScript Executes Code
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Code enters the &lt;strong&gt;Call Stack&lt;/strong&gt; one function at a time.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Each function &lt;strong&gt;completes&lt;/strong&gt; before the next one is run.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;3&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;If a function is waiting (e.g., timer, fetch API), it is offloaded to the &lt;strong&gt;Web APIs&lt;/strong&gt; and comes back later via the &lt;strong&gt;Event Loop&lt;/strong&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;JavaScript is &lt;strong&gt;fast&lt;/strong&gt; not because it is multi-threaded, but because it &lt;strong&gt;handles asynchronous tasks smartly&lt;/strong&gt; using the Event Loop.&lt;/p&gt;


&lt;h4&gt;
  
  
  Example with Asynchronous Behavior (Still Single-Threaded)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Start");

setTimeout(() =&amp;gt; {
    console.log("Timeout callback");
}, 2000);

console.log("End");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Callback Hell in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Callback Hell&lt;/strong&gt; refers to a situation in JavaScript where multiple nested callbacks make code &lt;strong&gt;difficult to read&lt;/strong&gt;, &lt;strong&gt;understand&lt;/strong&gt;, and &lt;strong&gt;maintain&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. What is a Callback?
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;callback&lt;/strong&gt; is a function passed as an argument to another function, and it is executed &lt;strong&gt;after some operation completes&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchData(callback) {
    setTimeout(() =&amp;gt; {
        console.log("Data fetched");
        callback();
    }, 1000);
}

fetchData(() =&amp;gt; {
    console.log("Callback executed");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. What is Callback Hell?
&lt;/h4&gt;

&lt;p&gt;When callbacks are nested inside other callbacks, it leads to deeply indented, hard-to-maintain code:&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(() =&amp;gt; {
    console.log("Step 1");
    setTimeout(() =&amp;gt; {
        console.log("Step 2");
        setTimeout(() =&amp;gt; {
            console.log("Step 3");
            setTimeout(() =&amp;gt; {
                console.log("Step 4");
            }, 1000);
        }, 1000);
    }, 1000);
}, 1000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Step 1&lt;br&gt;
Step 2&lt;br&gt;
Step 3&lt;br&gt;
Step 4&lt;/p&gt;


&lt;h3&gt;
  
  
  Promises in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Promise&lt;/strong&gt; in JavaScript is an object that represents the &lt;strong&gt;eventual completion (or failure)&lt;/strong&gt; of an &lt;strong&gt;asynchronous operation&lt;/strong&gt;, and its resulting value.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Why Promises?
&lt;/h4&gt;

&lt;p&gt;Before Promises, &lt;strong&gt;callbacks&lt;/strong&gt; were used to handle asynchronous code, which led to &lt;strong&gt;callback hell&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Promises solve this by offering a &lt;strong&gt;cleaner, chainable syntax&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  2. States of a Promise
&lt;/h4&gt;

&lt;p&gt;A Promise can be in one of three states:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;State&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Pending&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Initial state, neither fulfilled nor rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Fulfilled&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Operation completed successfully&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Rejected&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Operation failed&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  3. Creating a Promise
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {
    let success = true;

    if (success) {
        resolve("Data loaded!");
    } else {
        reject("Error loading data.");
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt; in JavaScript Promises
&lt;/h3&gt;

&lt;p&gt;JavaScript Promises come with &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt; methods to handle asynchronous operations &lt;strong&gt;successfully or with errors&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  &lt;code&gt;.then()&lt;/code&gt; – Handling Success
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;.then()&lt;/code&gt; method is used to specify what to do &lt;strong&gt;when the Promise is fulfilled&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;promise.then(onFulfilled);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let successPromise = new Promise((resolve, reject) =&amp;gt; {
    resolve("Task Successful!");
});

successPromise.then(result =&amp;gt; {
    console.log(result); // Output: Task Successful!
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  .catch() – Handling Errors
&lt;/h3&gt;

&lt;p&gt;The .catch() method is used to handle rejections (errors) in Promises.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;promise.catch(onRejected);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let failurePromise = new Promise((resolve, reject) =&amp;gt; {
    reject("❌ Task Failed!");
});

failurePromise
    .then(result =&amp;gt; {
        console.log(result);
    })
    .catch(error =&amp;gt; {
        console.log(error); // Output: ❌ Task Failed!
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Chaining .then() and .catch()
&lt;/h3&gt;

&lt;p&gt;You can chain multiple .then() calls. If any error occurs, it will be caught in .catch().&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;new Promise((resolve, reject) =&amp;gt; {
    resolve(10);
})
.then(num =&amp;gt; {
    return num * 2;
})
.then(result =&amp;gt; {
    console.log("Result:", result); // Output: Result: 20
})
.catch(err =&amp;gt; {
    console.error("Error:", err);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Promise Chaining in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Promise chaining&lt;/strong&gt; allows you to run multiple asynchronous operations &lt;strong&gt;in sequence&lt;/strong&gt;, where the &lt;strong&gt;output of one &lt;code&gt;.then()&lt;/code&gt; becomes the input of the next&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What is Promise Chaining?
&lt;/h4&gt;

&lt;p&gt;You can &lt;strong&gt;return a value or another Promise&lt;/strong&gt; from &lt;code&gt;.then()&lt;/code&gt; and chain further &lt;code&gt;.then()&lt;/code&gt; calls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetchData()
  .then(processData)
  .then(displayData)
  .catch(handleError);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Basic Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;new Promise((resolve, reject) =&amp;gt; {
    resolve(2);
})
.then(num =&amp;gt; {
    console.log("Step 1:", num); // Step 1: 2
    return num * 2;
})
.then(num =&amp;gt; {
    console.log("Step 2:", num); // Step 2: 4
    return num * 3;
})
.then(num =&amp;gt; {
    console.log("Step 3:", num); // Step 3: 12
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Returning a New Promise in the Chain
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function delayedStep(value, delay) {
    return new Promise(resolve =&amp;gt; {
        setTimeout(() =&amp;gt; {
            console.log("Step:", value);
            resolve(value);
        }, delay);
    });
}

delayedStep(1, 1000)
  .then(() =&amp;gt; delayedStep(2, 1000))
  .then(() =&amp;gt; delayedStep(3, 1000))
  .then(() =&amp;gt; console.log("All steps done!"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step: 1&lt;br&gt;
Step: 2&lt;br&gt;
Step: 3&lt;br&gt;
All steps done!&lt;/p&gt;
&lt;h3&gt;
  
  
  Results and Errors in JavaScript Promises
&lt;/h3&gt;

&lt;p&gt;JavaScript Promises allow you to handle &lt;strong&gt;successful results&lt;/strong&gt; and &lt;strong&gt;errors&lt;/strong&gt; in asynchronous operations in a clean, chainable way.&lt;/p&gt;


&lt;h4&gt;
  
  
  Handling Results with &lt;code&gt;.then()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;.then()&lt;/code&gt; method is used to &lt;strong&gt;receive the result&lt;/strong&gt; when a Promise is &lt;strong&gt;fulfilled&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let promise = new Promise((resolve, reject) =&amp;gt; {
    resolve("Data loaded successfully!");
});

promise.then(result =&amp;gt; {
    console.log("✅ Result:", result);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Handling Errors with .catch()
&lt;/h4&gt;

&lt;p&gt;The .catch() method is used to catch errors when a Promise is rejected or if an error is thrown in a .then() chain.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let errorPromise = new Promise((resolve, reject) =&amp;gt; {
    reject("Server error occurred.");
});

errorPromise
  .then(result =&amp;gt; {
      console.log("This will not run.");
  })
  .catch(error =&amp;gt; {
      console.log("❌ Error:", error);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Returning Values from .then()
&lt;/h4&gt;

&lt;p&gt;Each .then() passes its return value to the next .then() in the chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Promise.resolve(5)
  .then(num =&amp;gt; num * 2)
  .then(result =&amp;gt; {
      console.log("✅ Final Result:", result); // 10
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  async Functions in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;async&lt;/code&gt; functions&lt;/strong&gt; make writing asynchronous code in JavaScript &lt;strong&gt;simpler and more readable&lt;/strong&gt;, by allowing the use of &lt;code&gt;await&lt;/code&gt; to pause execution until a Promise is resolved or rejected.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What is an &lt;code&gt;async&lt;/code&gt; Function?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;An &lt;code&gt;async&lt;/code&gt; function &lt;strong&gt;always returns a Promise&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Inside an &lt;code&gt;async&lt;/code&gt; function, you can use the &lt;strong&gt;&lt;code&gt;await&lt;/code&gt; keyword&lt;/strong&gt; to wait for a Promise to resolve.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Basic Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function myFunction() {
    // code
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Example: Returning a Promise Automatically
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function greet() {
    return "Hello!";
}

greet().then(result =&amp;gt; {
    console.log(result); // Output: Hello!
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The return value is automatically wrapped in a Promise.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;await&lt;/code&gt; Keyword in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;await&lt;/code&gt;&lt;/strong&gt; keyword is used &lt;strong&gt;inside &lt;code&gt;async&lt;/code&gt; functions&lt;/strong&gt; to &lt;strong&gt;pause the execution&lt;/strong&gt; until a Promise is &lt;strong&gt;resolved&lt;/strong&gt; or &lt;strong&gt;rejected&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What Does &lt;code&gt;await&lt;/code&gt; Do?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Waits&lt;/strong&gt; for the result of a Promise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pauses execution&lt;/strong&gt; of the surrounding &lt;code&gt;async&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resumes&lt;/strong&gt; when the Promise is resolved (or throws an error if rejected).&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  2. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = await promise;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;await can only be used inside an async function (or top-level in modules).&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Example with Delay
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function delay(ms) {
    return new Promise(resolve =&amp;gt; setTimeout(resolve, ms));
}

async function run() {
    console.log("⏱️ Waiting...");
    await delay(2000);
    console.log("✅ Done after 2 seconds");
}

run();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;await delay(2000) pauses for 2 seconds before continuing.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Awaiting a Fetch Call
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function getUser() {
    const response = await fetch("https://jsonplaceholder.typicode.com/users/1");
    const user = await response.json();
    console.log("👤 User:", user);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;getUser();&lt;br&gt;
📌 await makes asynchronous HTTP calls look like synchronous code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Handling Rejections with &lt;code&gt;await&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;When using &lt;code&gt;await&lt;/code&gt; with Promises in &lt;code&gt;async&lt;/code&gt; functions, you must &lt;strong&gt;handle rejections&lt;/strong&gt; to prevent your app from crashing or behaving unexpectedly.&lt;/p&gt;


&lt;h4&gt;
  
  
  Why Handle Rejections?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If a Promise is &lt;strong&gt;rejected&lt;/strong&gt;, &lt;code&gt;await&lt;/code&gt; will &lt;strong&gt;throw an error&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Without handling, it may cause &lt;strong&gt;uncaught exceptions&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  1. Using &lt;code&gt;try...catch&lt;/code&gt; with &lt;code&gt;await&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The most common and reliable way to handle rejections is with a &lt;code&gt;try...catch&lt;/code&gt; block.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
    try {
        const response = await fetch("https://invalid.api.url");
        const data = await response.json();
        console.log("✅ Data:", data);
    } catch (error) {
        console.error("❌ Error fetching data:", error.message);
    }
}

fetchData();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Why Use?&lt;/p&gt;

&lt;p&gt;Gracefully catches any errors (like network failures, API issues, etc.).&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Custom Rejection Handling
&lt;/h4&gt;

&lt;p&gt;You can manually reject Promises and catch them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getUser(id) {
    return new Promise((resolve, reject) =&amp;gt; {
        if (id &amp;gt; 0) {
            resolve({ id, name: "Alice" });
        } else {
            reject("Invalid user ID");
        }
    });
}

async function loadUser() {
    try {
        const user = await getUser(-1);
        console.log("User:", user);
    } catch (err) {
        console.error("❌ Rejection:", err);
    }
}

loadUser();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Optional: Handle with .catch() after await
&lt;/h4&gt;

&lt;p&gt;You can also use .catch() inline with await, though it's less common than try...catch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const response = await fetch("/api/data").catch(err =&amp;gt; {
    console.error("❌ Fetch error:", err.message);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 Note: Further code will still execute even if this fails — be cautious.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is an API?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;API&lt;/strong&gt; stands for &lt;strong&gt;Application Programming Interface&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;An API is a &lt;strong&gt;set of rules&lt;/strong&gt; that allows one software application to &lt;strong&gt;communicate with another&lt;/strong&gt;. It defines &lt;strong&gt;how requests and responses should be formatted&lt;/strong&gt;, much like a &lt;strong&gt;contract between two programs&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Simple Definition
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;An &lt;strong&gt;API&lt;/strong&gt; is like a &lt;strong&gt;waiter&lt;/strong&gt; in a restaurant who takes your order (request), tells the kitchen (server), and brings back your food (response).&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  2. Real-World Analogy
&lt;/h4&gt;

&lt;h4&gt;
  
  
  You use an API every day:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Weather app fetches weather → it calls a &lt;strong&gt;weather API&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Instagram posts are loaded → it uses &lt;strong&gt;Instagram’s API&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Google Maps in your food app? → powered by the &lt;strong&gt;Maps API&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  3. Types of APIs
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Web API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Communication over the internet (HTTP/S)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Browser API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Built into the browser (e.g., &lt;code&gt;DOM&lt;/code&gt;, &lt;code&gt;fetch()&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Library API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Functions exposed by a library (e.g., jQuery)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Operating System API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Interfaces for OS features (e.g., file system)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  4. Web API Example (Using Fetch)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch("https://api.example.com/data")
  .then(response =&amp;gt; response.json())
  .then(data =&amp;gt; console.log(data))
  .catch(error =&amp;gt; console.error("❌ Error:", error));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. How Does an API Work?
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client (Frontend) ➡️ Sends Request ➡️
           Server (API) ➡️ Processes &amp;amp; Sends Response ➡️
                          Client uses the result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Common Data Format: JSON
&lt;/h4&gt;

&lt;p&gt;Most modern APIs communicate using JSON (JavaScript Object Notation).&lt;/p&gt;

&lt;p&gt;Example API Response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "Alice",
  "age": 30,
  "location": "Canada"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  7. HTTP Methods Used in APIs
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Method  Purpose
GET Read data
POST    Create data
PUT Update data
DELETE  Remove data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is JSON?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;JSON&lt;/strong&gt; stands for &lt;strong&gt;JavaScript Object Notation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It is a &lt;strong&gt;lightweight data format&lt;/strong&gt; used for &lt;strong&gt;storing and exchanging data&lt;/strong&gt; between servers and clients in a human-readable format.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Simple Definition
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;JSON is a &lt;strong&gt;text format&lt;/strong&gt; for representing &lt;strong&gt;structured data&lt;/strong&gt; (like objects and arrays) in a way that's &lt;strong&gt;easy to read&lt;/strong&gt; and &lt;strong&gt;easy for machines to parse&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  2. JSON Syntax Basics
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Data is in &lt;strong&gt;key-value pairs&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Data is &lt;strong&gt;separated by commas&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Curly braces &lt;code&gt;{}&lt;/code&gt; hold &lt;strong&gt;objects&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Square brackets &lt;code&gt;[]&lt;/code&gt; hold &lt;strong&gt;arrays&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Keys and string values &lt;strong&gt;must be in double quotes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Example JSON:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "Alice",
  "age": 25,
  "isStudent": false,
  "skills": ["JavaScript", "Python"],
  "address": {
    "city": "Toronto",
    "country": "Canada"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. JSON vs JavaScript Object
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature JSON    JavaScript Object
Quotes on keys  Required ("key")    Optional (key or "key")
Comments    ❌ Not allowed ✅ Allowed
Methods ❌ Not supported   ✅ Can include functions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. JSON in APIs
&lt;/h4&gt;

&lt;p&gt;APIs typically send and receive data in JSON format.&lt;/p&gt;

&lt;p&gt;Example with Fetch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch("https://api.example.com/user")
  .then(response =&amp;gt; response.json())
  .then(data =&amp;gt; {
    console.log(data.name); // Accessing JSON property
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Real-World Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;API responses&lt;/li&gt;
&lt;li&gt;Config files&lt;/li&gt;
&lt;li&gt;Storing data in localStorage&lt;/li&gt;
&lt;li&gt;Data exchange in mobile/web apps&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Accessing JSON Data in JavaScript
&lt;/h3&gt;

&lt;p&gt;JSON (JavaScript Object Notation) is a format used to exchange data. Once parsed into a JavaScript object, you can access its data using &lt;strong&gt;dot notation&lt;/strong&gt; or &lt;strong&gt;bracket notation&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Parsing JSON to JavaScript
&lt;/h4&gt;

&lt;p&gt;Before you access data, you must &lt;strong&gt;parse the JSON string&lt;/strong&gt; into a JavaScript object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let jsonString = '{"name": "Alice", "age": 25, "skills": ["JS", "Python"]}';

let user = JSON.parse(jsonString);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Accessing JSON Object Properties
&lt;/h4&gt;

&lt;p&gt;Dot Notation (most common):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(user.name);  // "Alice"
console.log(user.age);   // 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bracket Notation (useful for dynamic keys or invalid identifiers):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(user["skills"]);        // ["JS", "Python"]
console.log(user["name"]);          // "Alice"

let key = "age";
console.log(user[key]);             // 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Accessing Nested JSON Data
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "Bob",
  "address": {
    "city": "Toronto",
    "postal": "M4B1B3"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let data = JSON.parse('{"name":"Bob","address":{"city":"Toronto","postal":"M4B1B3"}}');

console.log(data.address.city);     // "Toronto"
console.log(data["address"]["postal"]); // "M4B1B3"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Accessing JSON Arrays
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "users": [
    { "id": 1, "name": "Alice" },
    { "id": 2, "name": "Bob" }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let data = JSON.parse('{"users":[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]}');

console.log(data.users[0].name);   // "Alice"
console.log(data.users[1]["id"]);  // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Looping Through JSON Data
&lt;/h4&gt;

&lt;p&gt;Using forEach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data.users.forEach(user =&amp;gt; {
    console.log(user.name);  // "Alice", "Bob"
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using for...of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let user of data.users) {
    console.log(user.id);   // 1, 2
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Accessing Before Parsing = ❌ Error
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let jsonData = '{"name": "John"}';

console.log(jsonData.name); // ❌ undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let parsed = JSON.parse(jsonData);
console.log(parsed.name);   // ✅ "John"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Top API Testing Tools for Developers
&lt;/h3&gt;

&lt;p&gt;API testing is essential for verifying that your backend services are &lt;strong&gt;working correctly, securely, and efficiently&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
These tools help &lt;strong&gt;send requests&lt;/strong&gt;, &lt;strong&gt;inspect responses&lt;/strong&gt;, &lt;strong&gt;automate tests&lt;/strong&gt;, and &lt;strong&gt;document APIs&lt;/strong&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Postman
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdl2bc050qpnwpbhxltm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdl2bc050qpnwpbhxltm.png" alt="Postman Logo" width="659" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Postman&lt;/strong&gt; is the most popular API testing tool with a user-friendly UI.&lt;/p&gt;
&lt;h4&gt;
  
  
  Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Create and send HTTP requests (GET, POST, PUT, DELETE)&lt;/li&gt;
&lt;li&gt;Organize requests in collections and folders&lt;/li&gt;
&lt;li&gt;Add environments and variables&lt;/li&gt;
&lt;li&gt;Automate tests with JavaScript&lt;/li&gt;
&lt;li&gt;View detailed request/response logs&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Best For:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Manual and automated API testing
&lt;/li&gt;
&lt;li&gt;Collaborating with teams&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 &lt;a href="https://www.postman.com" rel="noopener noreferrer"&gt;https://www.postman.com&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;
  
  
  2. Insomnia
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Insomnia&lt;/strong&gt; is a sleek, fast alternative to Postman with a focus on simplicity.&lt;/p&gt;
&lt;h4&gt;
  
  
  Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Support for REST, GraphQL, gRPC&lt;/li&gt;
&lt;li&gt;Environment variables&lt;/li&gt;
&lt;li&gt;JSON schema validation&lt;/li&gt;
&lt;li&gt;Plugin support and dark mode&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Best For:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Developers who prefer a minimal, keyboard-friendly tool&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 &lt;a href="https://insomnia.rest" rel="noopener noreferrer"&gt;https://insomnia.rest&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;
  
  
  3. Swagger (OpenAPI)
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Swagger UI&lt;/strong&gt; and &lt;strong&gt;SwaggerHub&lt;/strong&gt; help you document and test REST APIs.&lt;/p&gt;
&lt;h4&gt;
  
  
  Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Live API documentation&lt;/li&gt;
&lt;li&gt;Send requests from the UI&lt;/li&gt;
&lt;li&gt;Auto-generate client SDKs&lt;/li&gt;
&lt;li&gt;API mocking&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Best For:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Testing APIs from OpenAPI specs&lt;/li&gt;
&lt;li&gt;API-first development&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 &lt;a href="https://swagger.io/tools/swagger-ui/" rel="noopener noreferrer"&gt;https://swagger.io/tools/swagger-ui/&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;
  
  
  4. Hoppscotch (formerly Postwoman)
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Hoppscotch&lt;/strong&gt; is a fast, open-source, browser-based API client.&lt;/p&gt;
&lt;h4&gt;
  
  
  Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Lightweight and blazing fast&lt;/li&gt;
&lt;li&gt;Send requests for REST, GraphQL, WebSocket&lt;/li&gt;
&lt;li&gt;Open source and privacy-focused&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Best For:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Quick in-browser testing without installation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 &lt;a href="https://hoppscotch.io" rel="noopener noreferrer"&gt;https://hoppscotch.io&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;
  
  
  5. REST Assured (Java)
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;REST Assured&lt;/strong&gt; is a Java library for automating API tests.&lt;/p&gt;
&lt;h4&gt;
  
  
  Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Fluent syntax for writing tests&lt;/li&gt;
&lt;li&gt;Integrates with JUnit/TestNG&lt;/li&gt;
&lt;li&gt;Validates responses, headers, status codes&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Best For:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Backend developers using Java&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔗 &lt;a href="https://rest-assured.io" rel="noopener noreferrer"&gt;https://rest-assured.io&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;
  
  
  6. cURL (Command-Line)
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;cURL&lt;/strong&gt; is a command-line tool to send HTTP requests from the terminal.&lt;/p&gt;
&lt;h4&gt;
  
  
  Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Lightweight, no UI&lt;/li&gt;
&lt;li&gt;Works on Linux, Mac, Windows&lt;/li&gt;
&lt;li&gt;Perfect for scripting and automation&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST https://api.example.com/data -H "Content-Type: application/json" -d '{"name":"Alice"}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  7. JMeter
&lt;/h4&gt;

&lt;p&gt;Apache JMeter is great for performance and load testing APIs.&lt;/p&gt;
&lt;h4&gt;
  
  
  Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Simulate heavy traffic on APIs&lt;/li&gt;
&lt;li&gt;Record and replay requests&lt;/li&gt;
&lt;li&gt;Built-in reports and graphs&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What is AJAX?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;AJAX&lt;/strong&gt; stands for &lt;strong&gt;Asynchronous JavaScript and XML&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It is a technique that allows web pages to &lt;strong&gt;send and receive data from a server&lt;/strong&gt; &lt;strong&gt;asynchronously&lt;/strong&gt;, without reloading the entire page.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Simple Definition
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;AJAX enables your website to &lt;strong&gt;communicate with the server in the background&lt;/strong&gt;, updating parts of a web page &lt;strong&gt;without refreshing&lt;/strong&gt; the whole page.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h4&gt;
  
  
  2. Real-World Examples of AJAX
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Submitting a form without reloading the page&lt;/li&gt;
&lt;li&gt;Auto-search suggestions (like Google search)&lt;/li&gt;
&lt;li&gt;Live data updates (chat apps, news feeds)&lt;/li&gt;
&lt;li&gt;Loading content on scroll (infinite scroll)&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  3. Key Components of AJAX
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;JavaScript&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Controls the logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;XMLHttpRequest&lt;/strong&gt; or &lt;code&gt;fetch()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Sends requests to the server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;JSON/XML/HTML&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Formats the data being sent/received&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;DOM&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Updates the web page without reloading&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  4. Modern AJAX with &lt;code&gt;fetch()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;fetch("&lt;a href="https://jsonplaceholder.typicode.com/users/1%22" rel="noopener noreferrer"&gt;https://jsonplaceholder.typicode.com/users/1"&lt;/a&gt;)&lt;br&gt;
  .then(response =&amp;gt; response.json())&lt;br&gt;
  .then(data =&amp;gt; {&lt;br&gt;
    console.log("User:", data.name);&lt;br&gt;
  })&lt;br&gt;
  .catch(error =&amp;gt; {&lt;br&gt;
    console.error("Error fetching data:", error);&lt;br&gt;
  });&lt;/p&gt;

&lt;p&gt;No page reload, but user data is fetched and shown!&lt;/p&gt;
&lt;h3&gt;
  
  
  HTTP Verbs (Methods) Explained
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;HTTP verbs&lt;/strong&gt; (also known as &lt;strong&gt;HTTP methods&lt;/strong&gt;) define the type of &lt;strong&gt;action&lt;/strong&gt; to perform when making requests to a server.&lt;/p&gt;

&lt;p&gt;They are used in &lt;strong&gt;REST APIs&lt;/strong&gt; to map &lt;strong&gt;CRUD operations&lt;/strong&gt; (Create, Read, Update, Delete).&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Common HTTP Verbs
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Verb&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;th&gt;CRUD Equivalent&lt;/th&gt;
&lt;th&gt;Typical Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retrieve data&lt;/td&gt;
&lt;td&gt;Read&lt;/td&gt;
&lt;td&gt;Fetching user info, posts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;POST&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Create new data&lt;/td&gt;
&lt;td&gt;Create&lt;/td&gt;
&lt;td&gt;Submitting forms, creating users&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PUT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replace existing data&lt;/td&gt;
&lt;td&gt;Update&lt;/td&gt;
&lt;td&gt;Full update of a resource&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PATCH&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Partially update data&lt;/td&gt;
&lt;td&gt;Update&lt;/td&gt;
&lt;td&gt;Update specific fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DELETE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Remove data&lt;/td&gt;
&lt;td&gt;Delete&lt;/td&gt;
&lt;td&gt;Deleting a user or a record&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Adding Information in URLs (Query Parameters &amp;amp; URL Path)
&lt;/h3&gt;

&lt;p&gt;In web development, you often need to &lt;strong&gt;send information to the server&lt;/strong&gt; through the URL.&lt;br&gt;&lt;br&gt;
This can be done using:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Query Parameters&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Path Parameters&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h4&gt;
  
  
  1. Query Parameters (Key-Value Pairs)
&lt;/h4&gt;

&lt;p&gt;Query parameters are added to the URL after a &lt;code&gt;?&lt;/code&gt;, using &lt;code&gt;&amp;amp;&lt;/code&gt; to separate multiple values.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://example.com/api/users?name=Alice&amp;amp;age=25" rel="noopener noreferrer"&gt;https://example.com/api/users?name=Alice&amp;amp;age=25&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  JavaScript Example with &lt;code&gt;fetch()&lt;/code&gt;:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Alice";
let age = 25;

fetch(`https://example.com/api/users?name=${name}&amp;amp;age=${age}`)
  .then(res =&amp;gt; res.json())
  .then(data =&amp;gt; console.log(data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;📌 Use when sending optional or filter data&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Path Parameters (Clean URLs)
&lt;/h4&gt;

&lt;p&gt;Path parameters are embedded directly in the URL path, often used for resource IDs.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://example.com/api/users/123" rel="noopener noreferrer"&gt;https://example.com/api/users/123&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  JavaScript Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let userId = 123;

fetch(`https://example.com/api/users/${userId}`)
  .then(res =&amp;gt; res.json())
  .then(data =&amp;gt; console.log(data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;📌 Use when accessing specific resources (e.g., user, product, post).&lt;/p&gt;
&lt;h4&gt;
  
  
  3. When to Use Which?
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use Case    Path Parameter  Query Parameter
Get user by ID  /users/123  ❌
Filter/search users /users?name=John    ✅
Paginate data   /products?page=2    ✅
Fetch related resource  /users/123/posts    ✅ or Path-based
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  HTTP Headers Explained
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;HTTP headers&lt;/strong&gt; are key-value pairs sent between the &lt;strong&gt;client&lt;/strong&gt; and &lt;strong&gt;server&lt;/strong&gt; in every HTTP request and response.&lt;br&gt;&lt;br&gt;
They provide &lt;strong&gt;metadata&lt;/strong&gt; about the request/response and are essential for things like authentication, content type, caching, etc.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Types of HTTP Headers
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Request Headers&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sent by the client (browser, app) to the server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Response Headers&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sent by the server back to the client&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;General Headers&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Used by both request and response&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Entity Headers&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Define body content information (length, type, etc.)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  2. Common Request Headers
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Header&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Accept&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Specifies the media types the client can handle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Content-Type&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Type of data being sent (e.g., &lt;code&gt;application/json&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Authorization&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Authentication credentials (e.g., Bearer token)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;User-Agent&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Info about the client/browser&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Cache-Control&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Caching behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example of Request Headers in &lt;code&gt;fetch()&lt;/code&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch("https://api.example.com/data", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer your_token_here"
  },
  body: JSON.stringify({ name: "Alice" })
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Your First API Request Using &lt;code&gt;fetch()&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;fetch()&lt;/code&gt; method is a modern way to make &lt;strong&gt;HTTP requests&lt;/strong&gt; in JavaScript.&lt;br&gt;&lt;br&gt;
It returns a &lt;strong&gt;Promise&lt;/strong&gt;, making it ideal for handling asynchronous API calls like &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, and &lt;code&gt;DELETE&lt;/code&gt;.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(url, options)
  .then(response =&amp;gt; response.json())
  .then(data =&amp;gt; console.log(data))
  .catch(error =&amp;gt; console.error("❌ Error:", error));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Your First API Request Using &lt;code&gt;fetch()&lt;/code&gt; with &lt;code&gt;async/await&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Using &lt;code&gt;async/await&lt;/code&gt; with &lt;code&gt;fetch()&lt;/code&gt; provides a cleaner, more readable way to make asynchronous API requests in JavaScript.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
  try {
    const response = await fetch("https://example.com/api");
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error("❌ Error:", error.message);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Axios in JavaScript – HTTP Requests Made Easy
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; is a popular JavaScript library used to make &lt;strong&gt;HTTP requests&lt;/strong&gt; from the browser or Node.js.&lt;br&gt;&lt;br&gt;
It provides a simple, Promise-based API with powerful features for working with APIs.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✅ 1. Why Use Axios?
&lt;/h2&gt;

&lt;p&gt;Compared to the native &lt;code&gt;fetch()&lt;/code&gt; API, Axios offers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔁 Automatic JSON data transformation&lt;/li&gt;
&lt;li&gt;🌐 Better error handling&lt;/li&gt;
&lt;li&gt;📦 Built-in request/response interceptors&lt;/li&gt;
&lt;li&gt;🕒 Timeout support&lt;/li&gt;
&lt;li&gt;🌍 Supports older browsers (unlike &lt;code&gt;fetch&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;🧼 Cleaner syntax&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  2. Installing Axios
&lt;/h4&gt;
&lt;h4&gt;
  
  
  In a browser (CDN):
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  In a Node.js project:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;npm install axios&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Sending Headers with API Requests in JavaScript
&lt;/h3&gt;

&lt;p&gt;HTTP headers are used to pass &lt;strong&gt;additional information&lt;/strong&gt; between the &lt;strong&gt;client and server&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This includes data like &lt;strong&gt;content type&lt;/strong&gt;, &lt;strong&gt;authentication tokens&lt;/strong&gt;, &lt;strong&gt;API keys&lt;/strong&gt;, etc.&lt;/p&gt;

&lt;p&gt;You can send headers using both &lt;code&gt;fetch()&lt;/code&gt; and Axios.&lt;/p&gt;


&lt;h4&gt;
  
  
  1. Sending Headers with &lt;code&gt;fetch()&lt;/code&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch("https://api.example.com/data", {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer your_token_here"
  }
})
  .then(response =&amp;gt; response.json())
  .then(data =&amp;gt; console.log(data))
  .catch(error =&amp;gt; console.error("❌ Error:", error));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. Sending Headers with Axios
&lt;/h4&gt;

&lt;p&gt;Axios has a more concise syntax for headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.get("https://api.example.com/data", {
  headers: {
    "Authorization": "Bearer your_token_here"
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Activity: Using Query Strings to Filter API Results
&lt;/h3&gt;

&lt;p&gt;In this activity, you’ll learn how to &lt;strong&gt;use query strings&lt;/strong&gt; in API requests to &lt;strong&gt;filter data&lt;/strong&gt;, &lt;strong&gt;search records&lt;/strong&gt;, and &lt;strong&gt;pass parameters&lt;/strong&gt; through the URL.&lt;/p&gt;




&lt;h4&gt;
  
  
  Objective
&lt;/h4&gt;

&lt;p&gt;Make API requests that use &lt;strong&gt;query strings&lt;/strong&gt; to filter user data based on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name&lt;/li&gt;
&lt;li&gt;Limit of records&lt;/li&gt;
&lt;li&gt;Sort order&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  1. What is a Query String?
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;query string&lt;/strong&gt; is part of a URL that &lt;strong&gt;passes key-value pairs&lt;/strong&gt; to the server.&lt;/p&gt;

&lt;p&gt;It starts with a &lt;strong&gt;&lt;code&gt;?&lt;/code&gt;&lt;/strong&gt; and uses &lt;strong&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;&lt;/strong&gt; to separate multiple parameters.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;https://api.example.com/users?name=Alice&amp;amp;limit=5&lt;/code&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  2. Sample API (You Can Use)
&lt;/h4&gt;

&lt;p&gt;You can test this with the &lt;strong&gt;JSONPlaceholder&lt;/strong&gt; API:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://jsonplaceholder.typicode.com/users" rel="noopener noreferrer"&gt;https://jsonplaceholder.typicode.com/users&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This API doesn't support query filters, but we’ll &lt;strong&gt;simulate&lt;/strong&gt; how it would work.&lt;/p&gt;




&lt;h4&gt;
  
  
  3. Activity Instructions
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Step 1: Basic GET Request
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch("https://jsonplaceholder.typicode.com/users")
  .then(res =&amp;gt; res.json())
  .then(data =&amp;gt; console.log("All users:", data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Filter with a Query String
&lt;/h4&gt;

&lt;p&gt;Let’s simulate filtering by name (e.g., ?name=Leanne):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Leanne";

fetch(`https://jsonplaceholder.typicode.com/users?name=${encodeURIComponent(name)}`)
  .then(res =&amp;gt; res.json())
  .then(data =&amp;gt; {
    console.log(`Users matching name '${name}':`, data);
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Add More Query Parameters
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Leanne";
let sortBy = "username";

fetch(`https://jsonplaceholder.typicode.com/users?name=${name}&amp;amp;sort=${sortBy}`)
  .then(res =&amp;gt; res.json())
  .then(data =&amp;gt; console.log(data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 Even though JSONPlaceholder won’t apply the filter or sort, the URL structure is valid.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Activity Challenge
&lt;/h4&gt;

&lt;p&gt;Write a function that accepts filters and returns the request URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function buildQueryURL(baseURL, filters) {
  const query = new URLSearchParams(filters).toString();
  return `${baseURL}?${query}`;
}

const url = buildQueryURL("https://jsonplaceholder.typicode.com/users", {
  name: "Ervin",
  limit: 3,
  sort: "email"
});

console.log("Request URL:", url);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request URL: https://jsonplaceholder.typicode.com/users?name=Ervin&amp;amp;limit=3&amp;amp;sort=email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Object-Oriented Programming (OOP) in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript supports OOP principles like &lt;strong&gt;Encapsulation&lt;/strong&gt;, &lt;strong&gt;Inheritance&lt;/strong&gt;, &lt;strong&gt;Abstraction&lt;/strong&gt;, and &lt;strong&gt;Polymorphism&lt;/strong&gt; through objects and classes.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Objects
&lt;/h4&gt;

&lt;p&gt;Basic object with properties and methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = {
  name: "Bhupesh",
  age: 25,
  greet() {
    console.log(`Hello, ${this.name}`);
  }
};

user.greet(); // Hello, Bhupesh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Constructor Function
&lt;/h4&gt;

&lt;p&gt;Before ES6, constructor functions were used to create multiple instances.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(name, age) {
  this.name = name;
  this.age = age;
}

Person.prototype.greet = function() {
  console.log(`Hi, I'm ${this.name}`);
};

const p1 = new Person("Alice", 30);
p1.greet(); // Hi, I'm Alice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. ES6 Classes
&lt;/h4&gt;

&lt;p&gt;Modern syntax for creating blueprints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  greet() {
    console.log(`Hi, I'm ${this.name}`);
  }
}

const person1 = new Person("Bob", 28);
person1.greet(); // Hi, I'm Bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Inheritance
&lt;/h4&gt;

&lt;p&gt;One class can extend another:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal {
  constructor(name) {
    this.name = name;
  }

  speak() {
    console.log(`${this.name} makes a sound.`);
  }
}

class Dog extends Animal {
  speak() {
    console.log(`${this.name} barks.`);
  }
}

const d = new Dog("Rex");
d.speak(); // Rex barks.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Encapsulation
&lt;/h4&gt;

&lt;p&gt;Keep data protected using closures or #privateFields (modern JS):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class BankAccount {
  #balance = 0; // private field

  deposit(amount) {
    this.#balance += amount;
  }

  getBalance() {
    return this.#balance;
  }
}

const acc = new BankAccount();
acc.deposit(100);
console.log(acc.getBalance()); // 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Polymorphism
&lt;/h4&gt;

&lt;p&gt;Methods behave differently based on the object context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Shape {
  draw() {
    console.log("Drawing a shape...");
  }
}

class Circle extends Shape {
  draw() {
    console.log("Drawing a circle...");
  }
}

let shape1 = new Shape();
let shape2 = new Circle();

shape1.draw(); // Drawing a shape...
shape2.draw(); // Drawing a circle...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Object Prototypes in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript uses &lt;strong&gt;prototypal inheritance&lt;/strong&gt;, meaning objects can inherit properties and methods from a &lt;strong&gt;prototype&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. What is a Prototype?
&lt;/h4&gt;

&lt;p&gt;Every JavaScript object has a hidden internal property called &lt;code&gt;[[Prototype]]&lt;/code&gt;, accessible via:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.getPrototypeOf(obj)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Prototype Chain
&lt;/h4&gt;

&lt;p&gt;When you access a property or method on an object, JS looks up the prototype chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = {
  name: "Alice"
};

console.log(user.toString()); // inherited from Object.prototype
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  3. ES6 Classes Use Prototypes Under the Hood
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User {
  constructor(name) {
    this.name = name;
  }

  greet() {
    console.log(`Hello, ${this.name}`);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const u1 = new User("John");
u1.greet(); // Hello, John
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Here, greet() is on User.prototype.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Factory Functions in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Factory Function&lt;/strong&gt; is a function that returns a new object. It allows you to create multiple similar objects &lt;strong&gt;without using classes or constructor functions&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createUser(name, age) {
  return {
    name,
    age,
    greet() {
      console.log(`Hi, I'm ${this.name} and I'm ${this.age} years old.`);
    }
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user1 = createUser("Bhupesh", 25);
const user2 = createUser("Alice", 30);

user1.greet(); // Hi, I'm Bhupesh and I'm 25 years old.
user2.greet(); // Hi, I'm Alice and I'm 30 years old.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;new&lt;/code&gt; Operator in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;new&lt;/code&gt; operator in JavaScript is used to &lt;strong&gt;create instances of objects&lt;/strong&gt; from &lt;strong&gt;constructor functions&lt;/strong&gt; or &lt;strong&gt;classes&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  1. How &lt;code&gt;new&lt;/code&gt; Works
&lt;/h4&gt;

&lt;p&gt;When you use the &lt;code&gt;new&lt;/code&gt; keyword with a constructor function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(name) {
  this.name = name;
  this.sayHi = function () {
    console.log(`Hi, I'm ${this.name}`);
  };
}

const p1 = new Person("Bhupesh");
p1.sayHi(); // Hi, I'm Bhupesh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. What new Does Internally
&lt;/h4&gt;

&lt;p&gt;Using new Person("Bhupesh") is like doing the following steps manually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a blank object: {}&lt;/li&gt;
&lt;li&gt;Set its prototype: &lt;strong&gt;proto&lt;/strong&gt; = Person.prototype&lt;/li&gt;
&lt;li&gt;Bind this to the new object&lt;/li&gt;
&lt;li&gt;Run the constructor function&lt;/li&gt;
&lt;li&gt;Return the new object&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Using new with ES6 Classes
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
  constructor(brand) {
    this.brand = brand;
  }

  drive() {
    console.log(`${this.brand} is driving.`);
  }
}

const car1 = new Car("Tesla");
car1.drive(); // Tesla is driving.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Without new — Common Mistake
&lt;/h4&gt;

&lt;p&gt;If you forget new, this becomes undefined or refers to the global object (in non-strict mode):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Animal(name) {
  this.name = name;
}

const a = Animal("Tiger");
console.log(a); // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Classes in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript introduced the &lt;code&gt;class&lt;/code&gt; syntax in &lt;strong&gt;ES6 (ECMAScript 2015)&lt;/strong&gt; as a cleaner, more familiar way to create objects and handle inheritance.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Under the hood, JavaScript classes are syntactic sugar over its prototype-based inheritance model.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  1. Basic Class Declaration
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  greet() {
    console.log(`Hi, I'm ${this.name} and I'm ${this.age} years old.`);
  }
}

const p1 = new Person("Bhupesh", 25);
p1.greet(); // Hi, I'm Bhupesh and I'm 25 years old.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Using super() to Access Parent Class
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Employee {
  constructor(name) {
    this.name = name;
  }
}

class Manager extends Employee {
  constructor(name, department) {
    super(name); // Call parent constructor
    this.department = department;
  }

  info() {
    console.log(`${this.name} manages ${this.department}`);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Class Fields (Public and Private)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Counter {
  count = 0; // Public field
  #secret = 42; // Private field (ES2022+)

  increment() {
    this.count++;
  }

  revealSecret() {
    return this.#secret;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Static Methods
&lt;/h4&gt;

&lt;p&gt;Static methods are called on the class, not instances.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MathUtils {
  static square(x) {
    return x * x;
  }
}

console.log(MathUtils.square(4)); // 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Syntax Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class declaration&lt;/td&gt;
&lt;td&gt;&lt;code&gt;class MyClass {}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Constructor&lt;/td&gt;
&lt;td&gt;&lt;code&gt;constructor(args) { ... }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Method&lt;/td&gt;
&lt;td&gt;&lt;code&gt;methodName() {}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inheritance&lt;/td&gt;
&lt;td&gt;&lt;code&gt;class B extends A&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Call parent&lt;/td&gt;
&lt;td&gt;&lt;code&gt;super()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Static method&lt;/td&gt;
&lt;td&gt;&lt;code&gt;static myMethod()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Private field&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#myPrivate = value&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  JS (OOP) Summary Sheet
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Q1. What is Object-Oriented Programming (OOP)?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of &lt;strong&gt;objects and classes&lt;/strong&gt;. It structures code into &lt;strong&gt;reusable blueprints (classes)&lt;/strong&gt; that can be used to create individual &lt;strong&gt;instances (objects)&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  Q2. What are some benefits of using OOP in JavaScript?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧱 Improved code organization
&lt;/li&gt;
&lt;li&gt;🔁 Reusability of code
&lt;/li&gt;
&lt;li&gt;🔧 Easier code maintenance
&lt;/li&gt;
&lt;li&gt;🌐 Real-world modeling using objects
&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Q3. What is the difference between an object and a class in JavaScript?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Object:&lt;/strong&gt; An instance containing properties and methods.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Class:&lt;/strong&gt; A blueprint for creating objects.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objects are created from classes or constructor functions.&lt;/p&gt;


&lt;h3&gt;
  
  
  Q4. What is a constructor function in JS?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A constructor function is a &lt;strong&gt;special function&lt;/strong&gt; used to create and initialize objects in JavaScript. When called with the &lt;code&gt;new&lt;/code&gt; keyword, it sets up properties and methods for the new object.&lt;/p&gt;


&lt;h3&gt;
  
  
  Q5. What is a prototype chain in JavaScript?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Every JavaScript object has a &lt;strong&gt;prototype&lt;/strong&gt;, and that prototype is also an object. This forms a &lt;strong&gt;prototype chain&lt;/strong&gt;, which continues until it reaches &lt;code&gt;null&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let obj = {};
console.log(Object.getPrototypeOf(obj)); // =&amp;gt; Object.prototype
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Q6. What is the difference between a constructor and a class in JS?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Constructor Function: A function used to create and initialize an object.&lt;/li&gt;
&lt;li&gt;Class: A syntactic sugar introduced in ES6 that makes constructor functions easier to work with.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both serve the same purpose, but class syntax is cleaner and more intuitive.&lt;/p&gt;

&lt;h3&gt;
  
  
  Q7. Why is the new keyword used in JavaScript?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;br&gt;
The new keyword is used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new object&lt;/li&gt;
&lt;li&gt;Set the constructor's this to that object&lt;/li&gt;
&lt;li&gt;Return the newly created object&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Q8. What is Inheritance in OOP?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;br&gt;
Inheritance allows a class to inherit properties and methods from another class. This promotes reusability and models real-world relationships.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal {
  speak() {
    console.log("Animal speaks");
  }
}

class Dog extends Animal {
  speak() {
    console.log("Dog barks");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Q9. What is the super keyword in JS?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;br&gt;
super is used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access and call functions on an object’s parent class.&lt;/li&gt;
&lt;li&gt;Must be used before this in derived class constructors.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Parent {
  constructor(name) {
    this.name = name;
  }
}

class Child extends Parent {
  constructor(name, age) {
    super(name); // Calls Parent constructor
    this.age = age;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Q10. What will be the output of the following?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Box {
  area() {
    return "Box area is 100";
  }
}

class Square extends Box {
  area() {
    return "Square area is 16";
  }
}

const obj = new Square();
console.log(obj.area());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt;&lt;br&gt;
Output: Square area is 16&lt;br&gt;
➡ Because the child class method overrides the parent class method.&lt;/p&gt;

&lt;p&gt;That’s a wrap on &lt;strong&gt;JavaScript Guide – Part 2!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Build a Simple To-Do App with JavaScript – A Step-by-Step Guide</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Sat, 15 Feb 2025 22:54:14 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/build-a-simple-to-do-app-with-javascript-a-step-by-step-guide-kkd</link>
      <guid>https://dev.to/_bhupeshk_/build-a-simple-to-do-app-with-javascript-a-step-by-step-guide-kkd</guid>
      <description>&lt;p&gt;Managing daily tasks can be overwhelming, but what if you could &lt;strong&gt;build your own To-Do App&lt;/strong&gt;?&lt;br&gt;&lt;br&gt;
In this &lt;strong&gt;beginner-friendly guide&lt;/strong&gt;, we will walk through &lt;strong&gt;every step&lt;/strong&gt; to create a &lt;strong&gt;fully functional To-Do App&lt;/strong&gt; using &lt;strong&gt;HTML, CSS, and JavaScript&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What You’ll Learn:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to build a simple &lt;strong&gt;To-Do App UI&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;JavaScript to add, view, complete, and delete tasks&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Storing tasks &lt;strong&gt;persistently using localStorage&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Writing clean &lt;strong&gt;HTML, CSS, and JavaScript code&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Organizing your project for &lt;strong&gt;scalability &amp;amp; maintainability&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;GitHub Repo:&lt;/strong&gt; &lt;a href="https://github.com/bhupeshk3014/to-do-app" rel="noopener noreferrer"&gt;To-Do App&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl81izckwus5gegz1ytpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl81izckwus5gegz1ytpq.png" alt="To-Do App Screenshot 1" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqyu22tl9ulqduhzigg2.png" alt="To-Do App Screenshot 2" width="800" height="422"&gt;
&lt;/h2&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;📂 Step 1: Project Setup&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before we start coding, let's &lt;strong&gt;set up our project&lt;/strong&gt; structure.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create a folder named &lt;code&gt;to-do-app&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Inside this folder, create the following files:
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;to-do-app/  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    index.html     → Main HTML structure
&lt;/li&gt;
&lt;li&gt;    styles.css     → Styles for the app
&lt;/li&gt;
&lt;li&gt;    script.js      → JavaScript logic
&lt;/li&gt;
&lt;li&gt;    README.md      → Documentation
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s start coding! 🚀  &lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;📜 Step 2: Creating the HTML Structure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We need a &lt;strong&gt;basic UI&lt;/strong&gt; for our app, with buttons for adding, viewing, completing, and deleting tasks.&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Create an &lt;code&gt;index.html&lt;/code&gt; file and add this code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Minimal To-Do App&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="styles.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

    &amp;lt;div class="container"&amp;gt;
        &amp;lt;h2&amp;gt;📝 To-Do App&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;Manage your tasks easily.&amp;lt;/p&amp;gt;
        &amp;lt;div class="menu"&amp;gt;
            &amp;lt;button class="view" onclick="viewTasks()"&amp;gt;📋 View Tasks&amp;lt;/button&amp;gt;
            &amp;lt;button class="add" onclick="addTask()"&amp;gt;➕ Add Task&amp;lt;/button&amp;gt;
            &amp;lt;button class="complete" onclick="completeTask()"&amp;gt;✅ Complete Task&amp;lt;/button&amp;gt;
            &amp;lt;button class="delete" onclick="deleteTask()"&amp;gt;❌ Delete Task&amp;lt;/button&amp;gt;
            &amp;lt;button class="exit" onclick="exitApp()"&amp;gt;🚪 Exit&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Understanding the Code&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Buttons call JavaScript functions&lt;/strong&gt; to perform actions.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS is linked&lt;/strong&gt; (&lt;code&gt;styles.css&lt;/code&gt;) for styling the app.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript is linked&lt;/strong&gt; (&lt;code&gt;script.js&lt;/code&gt;) to add functionality. &lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎨 &lt;strong&gt;Step 3: Styling the App&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now, let’s make our app look &lt;strong&gt;clean and modern&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Create a &lt;code&gt;styles.css&lt;/code&gt; file and add this code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&amp;amp;display=swap');

body {
    font-family: 'Inter', sans-serif;
    background-color: #f4f4f9;
    text-align: center;
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Centered App Container */
.container {
    background: #ffffff;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 90%;
}

h2 {
    color: #333;
}

p {
    font-size: 14px;
    color: #666;
}

/* Buttons */
button {
    padding: 12px;
    font-size: 16px;
    border: none;
    cursor: pointer;
    width: 100%;
    border-radius: 8px;
    font-weight: 600;
    outline: none;
    transition: all 0.3s ease-in-out;
}

.view { background-color: #3498db; color: white; }
.add { background-color: #2ecc71; color: white; }
.complete { background-color: #f1c40f; color: black; }
.delete { background-color: #e74c3c; color: white; }
.exit { background-color: #95a5a6; color: white; }

button:hover {
    opacity: 0.85;
    transform: translateY(-2px);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Key Takeaways&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Uses &lt;code&gt;Inter&lt;/code&gt; font&lt;/strong&gt; for modern typography.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adds hover effects&lt;/strong&gt; on buttons.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Applies a centered white card layout&lt;/strong&gt; for a clean UI.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 &lt;strong&gt;Step 4: Adding JavaScript Logic&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now, let's add &lt;strong&gt;functionality&lt;/strong&gt; to our To-Do App.&lt;/p&gt;

&lt;p&gt;This guide explains the JavaScript logic used in the To-Do App. Each function plays an important role in managing tasks, storing them, and ensuring they persist even after refreshing the page.  &lt;/p&gt;

&lt;p&gt;The To-Do App allows users to:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add tasks via &lt;code&gt;prompt()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;View tasks using &lt;code&gt;alert()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Mark tasks as completed
&lt;/li&gt;
&lt;li&gt;Delete tasks
&lt;/li&gt;
&lt;li&gt;Store tasks persistently using &lt;code&gt;localStorage&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript is responsible for managing tasks, storing data, and handling user interactions.&lt;/p&gt;




&lt;h3&gt;
  
  
  Storing and Loading Tasks (&lt;code&gt;localStorage&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Before working with tasks, they need to persist across browser sessions.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the app loads, it retrieves saved tasks from &lt;code&gt;localStorage&lt;/code&gt;, ensuring they don't disappear after a refresh.
&lt;/li&gt;
&lt;li&gt;If no tasks exist, an empty array is initialized.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;localStorage.getItem("tasks")&lt;/code&gt; fetches saved tasks, and &lt;code&gt;JSON.parse()&lt;/code&gt; converts the stored string back into an array.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;localStorage.setItem("tasks", JSON.stringify(tasks))&lt;/code&gt; updates the task list whenever a change is made.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Viewing Tasks (&lt;code&gt;viewTasks()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;This function displays all tasks in an alert box so users can see their to-do list.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the task list is empty, an alert notifies the user that no tasks exist.
&lt;/li&gt;
&lt;li&gt;The function loops through all tasks and formats them:

&lt;ul&gt;
&lt;li&gt;Completed tasks show a checkmark &lt;code&gt;[✔]&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Pending tasks show an empty box &lt;code&gt;[ ]&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Finally, the formatted list is displayed in an alert box.
&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  Key Concepts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Loops (&lt;code&gt;forEach&lt;/code&gt;) iterate over the task list.
&lt;/li&gt;
&lt;li&gt;Ternary Operator (&lt;code&gt;? :&lt;/code&gt;) checks if a task is completed.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Adding a Task (&lt;code&gt;addTask()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Users can add a new task to their list using this function.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;prompt()&lt;/code&gt; asks the user for task input.
&lt;/li&gt;
&lt;li&gt;The task is stored as an object with &lt;code&gt;{ text: "task name", completed: false }&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;The task is pushed into the array and saved in &lt;code&gt;localStorage&lt;/code&gt; to ensure persistence.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Key Concepts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;User input is taken via &lt;code&gt;prompt()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Objects store task details (text and completion status).
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.push()&lt;/code&gt; method adds a new task to the array.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Marking a Task as Completed (&lt;code&gt;completeTask()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Users can mark tasks as completed or undo completion.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The task list is displayed.
&lt;/li&gt;
&lt;li&gt;The user enters the task number they want to complete.
&lt;/li&gt;
&lt;li&gt;The task’s completion status is toggled (if incomplete, it becomes complete and vice versa).
&lt;/li&gt;
&lt;li&gt;The updated list is saved in &lt;code&gt;localStorage&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Key Concepts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Boolean toggling (&lt;code&gt;!variable&lt;/code&gt;) flips &lt;code&gt;true&lt;/code&gt; to &lt;code&gt;false&lt;/code&gt; and vice versa.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parseInt()&lt;/code&gt; converts user input into a number.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Deleting a Task (&lt;code&gt;deleteTask()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Users can remove a task from their to-do list.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The task list is displayed so users can see the task numbers.
&lt;/li&gt;
&lt;li&gt;The user enters the task number they want to delete.
&lt;/li&gt;
&lt;li&gt;The task is removed using &lt;code&gt;.splice()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;The updated task list is saved to &lt;code&gt;localStorage&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Key Concepts
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.splice(index, 1)&lt;/code&gt; removes one item at the given index.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Saving Tasks (&lt;code&gt;saveTasks()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Whenever the task list is updated (added, completed, or deleted), it needs to be saved.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Converts the &lt;code&gt;tasks&lt;/code&gt; array into a JSON string using &lt;code&gt;JSON.stringify()&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Saves it in &lt;code&gt;localStorage&lt;/code&gt; using &lt;code&gt;setItem()&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Key Concept
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;localStorage&lt;/code&gt; only supports string data, so arrays and objects need conversion.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Exiting the App (&lt;code&gt;exitApp()&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;This function simply displays a thank-you message when users exit the app.  &lt;/p&gt;

&lt;h4&gt;
  
  
  Key Concept
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Uses &lt;code&gt;alert()&lt;/code&gt; to show a simple exit message.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;By understanding this JavaScript code, you now know:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How JavaScript manipulates and stores data
&lt;/li&gt;
&lt;li&gt;How &lt;code&gt;localStorage&lt;/code&gt; keeps data persistent
&lt;/li&gt;
&lt;li&gt;How user input is handled with &lt;code&gt;prompt()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;How tasks are dynamically updated in an array
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Now, you fully understand the To-Do App’s JavaScript logic. Below is the full JavaScript code for reference:&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Create a &lt;code&gt;script.js&lt;/code&gt; file and add:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Load tasks from localStorage
let tasks = JSON.parse(localStorage.getItem("tasks")) || [];

// Function to display tasks
function viewTasks() {
    if (tasks.length === 0) {
        alert("No tasks yet. Add one!");
        return;
    }
    let taskList = "Your To-Do List:\n";
    tasks.forEach((task, index) =&amp;gt; {
        let status = task.completed ? "[✔]" : "[ ]";
        taskList += `${index + 1}. ${status} ${task.text}\n`;
    });
    alert(taskList);
}

// Function to add a task
function addTask() {
    let taskText = prompt("Enter your task:");
    if (taskText) {
        tasks.push({ text: taskText, completed: false });
        saveTasks();
        alert("Task added successfully!");
    }
}

// Function to mark a task as completed
function completeTask() {
    viewTasks();
    let taskNumber = parseInt(prompt("Enter task number to mark as completed:"));
    if (!isNaN(taskNumber) &amp;amp;&amp;amp; taskNumber &amp;gt; 0 &amp;amp;&amp;amp; taskNumber &amp;lt;= tasks.length) {
        tasks[taskNumber - 1].completed = !tasks[taskNumber - 1].completed;
        saveTasks();
        alert("Task updated!");
    }
}

// Function to delete a task
function deleteTask() {
    viewTasks();
    let taskNumber = parseInt(prompt("Enter task number to delete:"));
    if (!isNaN(taskNumber) &amp;amp;&amp;amp; taskNumber &amp;gt; 0 &amp;amp;&amp;amp; taskNumber &amp;lt;= tasks.length) {
        tasks.splice(taskNumber - 1, 1);
        saveTasks();
        alert("Task deleted!");
    }
}

// Function to save tasks to localStorage
function saveTasks() {
    localStorage.setItem("tasks", JSON.stringify(tasks));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🎯 &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;By completing this guide, you now have:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A working To-Do App&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Basic JavaScript skills&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LocalStorage implementation&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A clean, responsive UI&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;🚀 &lt;strong&gt;Try it out, experiment, and enhance your skills!&lt;/strong&gt; 😊  &lt;/p&gt;

</description>
      <category>development</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>coding</category>
    </item>
    <item>
      <title>Web Dev Day 6: JavaScript Guide Part 1</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Sun, 09 Feb 2025 00:37:54 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/web-dev-day-5-javascript-guide-4ngf</link>
      <guid>https://dev.to/_bhupeshk_/web-dev-day-5-javascript-guide-4ngf</guid>
      <description>&lt;h3&gt;
  
  
  What is a Variable?
&lt;/h3&gt;

&lt;p&gt;A variable in JavaScript is a named container that holds a value. It allows us to store, update, and retrieve data dynamically.&lt;br&gt;&lt;br&gt;
JavaScript provides three ways to declare variables:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; (old syntax)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; (modern)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const&lt;/code&gt; (for constants)
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Bhupesh"; 
const age = 25; 
var country = "Canada";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Data Types in JS
&lt;/h3&gt;

&lt;p&gt;JavaScript has &lt;strong&gt;primitive&lt;/strong&gt; and &lt;strong&gt;non-primitive&lt;/strong&gt; data types.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Primitive Data Types&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;These are immutable and stored directly in memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;String&lt;/strong&gt; → &lt;code&gt;"Hello"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Number&lt;/strong&gt; → &lt;code&gt;42&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boolean&lt;/strong&gt; → &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Undefined&lt;/strong&gt; → &lt;code&gt;let x;&lt;/code&gt; (not assigned)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Null&lt;/strong&gt; → &lt;code&gt;let y = null;&lt;/code&gt; (empty value)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BigInt&lt;/strong&gt; → &lt;code&gt;12345678901234567890123n&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Symbol&lt;/strong&gt; → &lt;code&gt;Symbol('unique')&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Non-Primitive Data Types&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;These are reference types and stored as objects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Objects&lt;/strong&gt; → &lt;code&gt;{ name: "John", age: 30 }&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arrays&lt;/strong&gt; → &lt;code&gt;["apple", "banana", "cherry"]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Functions&lt;/strong&gt; →
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  function greet() { 
      console.log("Hello!"); 
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Numbers in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript has only &lt;strong&gt;one type&lt;/strong&gt; for numbers: &lt;strong&gt;floating-point numbers&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 10;       // Integer
let b = 10.5;     // Float
let c = 1e3;      // Scientific notation (1000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Special Number Values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Infinity → &lt;code&gt;console.log(1 / 0);&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;-Infinity → &lt;code&gt;console.log(-1 / 0);&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;NaN (Not-a-Number) → &lt;code&gt;console.log("hello" * 2);&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Operations in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript supports the following &lt;strong&gt;operators&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Arithmetic Operators&lt;/strong&gt;: &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;%&lt;/code&gt;, &lt;code&gt;**&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comparison Operators&lt;/strong&gt;: &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;===&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;, &lt;code&gt;!==&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logical Operators&lt;/strong&gt;: &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bitwise Operators&lt;/strong&gt;: &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ternary Operator&lt;/strong&gt;: &lt;code&gt;condition ? trueValue : falseValue&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 + 2);  // 7
console.log(10 / 2); // 5
console.log(3 ** 2); // 9 (Exponentiation)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  NaN in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;NaN&lt;/code&gt; stands for &lt;strong&gt;"Not-a-Number."&lt;/strong&gt; It occurs when an operation does not yield a valid number.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("hello" * 2); // NaN
console.log(0 / 0);       // NaN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Operator Precedence in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Operator precedence&lt;/strong&gt; determines how expressions are evaluated in JavaScript.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator Type&lt;/th&gt;
&lt;th&gt;Operators&lt;/th&gt;
&lt;th&gt;Precedence&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Parentheses&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Highest&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Exponentiation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;**&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Multiplication, Division, Modulus&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;%&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Addition, Subtraction&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Relational&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Equality&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;==&lt;/code&gt;, &lt;code&gt;===&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;, &lt;code&gt;!==&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Logical AND&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Logical OR&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;`&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;{% raw %}&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 + 3 * 2);    // 11 (Multiplication first)
console.log((5 + 3) * 2);  // 16 (Parentheses first)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;let&lt;/code&gt; Keyword
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;let&lt;/code&gt; keyword was &lt;strong&gt;introduced in ES6&lt;/strong&gt;. It has the following properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Block-scoped&lt;/strong&gt; (Only accessible within the block &lt;code&gt;{}&lt;/code&gt; it is declared in).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Can be reassigned&lt;/strong&gt; but &lt;strong&gt;cannot be redeclared&lt;/strong&gt; within the same scope.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 10;
x = 20;  // ✅ Allowed

let x = 30; // ❌ Error (Cannot redeclare)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;const&lt;/code&gt; Keyword
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;const&lt;/code&gt; keyword has the following properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Block-scoped&lt;/strong&gt; (Like &lt;code&gt;let&lt;/code&gt;, it is confined within the block &lt;code&gt;{}&lt;/code&gt; it is declared in).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cannot be reassigned&lt;/strong&gt; after declaration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cannot be redeclared&lt;/strong&gt; in the same scope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Must be initialized&lt;/strong&gt; when declared.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const PI = 3.1416;
PI = 3.14; // ❌ Error (Cannot reassign)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;var&lt;/code&gt; Keyword (Old Syntax)
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;var&lt;/code&gt; keyword is &lt;strong&gt;function-scoped&lt;/strong&gt;, meaning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Can be redeclared&lt;/strong&gt; and &lt;strong&gt;reassigned&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not recommended&lt;/strong&gt; in modern JavaScript due to scoping issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var name = "Alice";
var name = "Bob";  // ✅ Allowed (but not good practice)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Assignment Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;Assignment operators are used to &lt;strong&gt;assign values to variables&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Assigns &lt;code&gt;5&lt;/code&gt; to &lt;code&gt;x&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x += 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x + 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x -= 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x - 3&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x *= 4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x * 4&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x /= 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x / 5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x %= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x % 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h3&gt;
  
  
  Unary Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;Unary operators operate on a &lt;strong&gt;single operand&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;+&lt;/code&gt; (Unary plus)&lt;/td&gt;
&lt;td&gt;Converts value to a number&lt;/td&gt;
&lt;td&gt;&lt;code&gt;+"42"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;42&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;-&lt;/code&gt; (Unary minus)&lt;/td&gt;
&lt;td&gt;Negates a number&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-10&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-10&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;++&lt;/code&gt; (Increment)&lt;/td&gt;
&lt;td&gt;Increases value by &lt;code&gt;1&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let x = 1; x++&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;--&lt;/code&gt; (Decrement)&lt;/td&gt;
&lt;td&gt;Decreases value by &lt;code&gt;1&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let y = 2; y--&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;typeof&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns the type of a value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;typeof 42&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;"number"&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h3&gt;
  
  
  Identifiers Rule in JavaScript
&lt;/h3&gt;

&lt;p&gt;Identifiers are &lt;strong&gt;names used for variables, functions, and objects&lt;/strong&gt;. JavaScript follows these rules:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Valid Identifiers&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can include &lt;strong&gt;letters, digits, underscores (&lt;code&gt;_&lt;/code&gt;)&lt;/strong&gt;, and &lt;strong&gt;dollar signs (&lt;code&gt;$&lt;/code&gt;)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cannot start with a digit&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript is case-sensitive&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Valid Identifiers:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let firstName;
let _privateVar;
let $price;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Invalid Identifiers in JavaScript
&lt;/h4&gt;

&lt;p&gt;JavaScript has strict rules for naming &lt;strong&gt;identifiers&lt;/strong&gt;. The following are &lt;strong&gt;invalid identifiers&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let 2name;    // ❌ Error (Cannot start with a digit)
let my-name;  // ❌ Error (Hyphens are not allowed)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  camelCase Naming Convention in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript follows the &lt;strong&gt;camelCase&lt;/strong&gt; naming convention, where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first word is lowercase.&lt;/li&gt;
&lt;li&gt;Each subsequent word starts with an uppercase letter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let userName;
let totalAmount;
let firstName;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Boolean in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Boolean&lt;/strong&gt; represents either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let isLoggedIn = true;
let hasDiscount = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boolean Conversion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Boolean(0));        // false
console.log(Boolean("Hello"));  // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is TypeScript?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;TypeScript&lt;/strong&gt; is a &lt;strong&gt;superset of JavaScript&lt;/strong&gt; that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Adds static typing&lt;/strong&gt; to JavaScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prevents runtime errors&lt;/strong&gt; by catching issues during development.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compiles to JavaScript&lt;/strong&gt;, making it compatible with all JS environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Static vs. Dynamic Typing:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TypeScript&lt;/strong&gt; is &lt;strong&gt;statically typed&lt;/strong&gt;, meaning variable types are checked at compile time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript&lt;/strong&gt; is &lt;strong&gt;dynamically typed&lt;/strong&gt;, meaning types are inferred at runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age: number = 25;  // TypeScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  String in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;string&lt;/strong&gt; is a sequence of characters enclosed in &lt;strong&gt;quotes (&lt;code&gt;""&lt;/code&gt; or &lt;code&gt;''&lt;/code&gt;)&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let greeting = "Hello, World!";
console.log(greeting.length); // 13
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  String Indices in JavaScript
&lt;/h3&gt;

&lt;p&gt;Each character in a &lt;strong&gt;string&lt;/strong&gt; has an &lt;strong&gt;index&lt;/strong&gt;, starting from &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = "JavaScript";
console.log(str[0]);             // "J"
console.log(str[str.length - 1]); // "t"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  String Concatenation in JavaScript
&lt;/h3&gt;

&lt;p&gt;Concatenation is the process of &lt;strong&gt;joining two or more strings together&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Methods of Concatenation:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Using the &lt;code&gt;+&lt;/code&gt; operator&lt;/strong&gt; (Most common)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Using the &lt;code&gt;.concat()&lt;/code&gt; method&lt;/strong&gt; (Less common)&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Hello" + " " + "World"); // "Hello World"
console.log("Hi".concat(" there!"));  // "Hi there!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; are &lt;strong&gt;special values&lt;/strong&gt; that represent &lt;strong&gt;the absence of a value&lt;/strong&gt;, but they have different meanings.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;undefined&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A variable is &lt;code&gt;undefined&lt;/code&gt; when it is &lt;strong&gt;declared but not assigned a value&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;It is the &lt;strong&gt;default value&lt;/strong&gt; of an uninitialized variable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x;
console.log(x); // undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;null&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;code&gt;null&lt;/code&gt; represents an &lt;strong&gt;intentional absence of any object value&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It signifies that a variable &lt;strong&gt;intentionally holds no value&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt; must be &lt;strong&gt;explicitly assigned&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let y = null;
console.log(y); // null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;console.log()&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;console.log()&lt;/code&gt; is a built-in JavaScript method used to print &lt;strong&gt;output to the console&lt;/strong&gt;.&lt;/p&gt;




&lt;h4&gt;
  
  
  Usage:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Hello, World!"); // Output: Hello, World!
console.log(5 + 3);          // Output: 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Linking a JavaScript File to HTML
&lt;/h3&gt;

&lt;p&gt;To use JavaScript in an HTML file, you need to &lt;strong&gt;link an external JavaScript file&lt;/strong&gt; using the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;




&lt;h4&gt;
  
  
  How to Link an External JavaScript File
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Create an HTML file (&lt;code&gt;index.html&lt;/code&gt;)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create a JavaScript file (&lt;code&gt;script.js&lt;/code&gt;)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Link the JavaScript file in the HTML file&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;index.html&lt;/code&gt;
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;JavaScript Linking&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Welcome to JavaScript&amp;lt;/h1&amp;gt;

    &amp;lt;!-- Linking JavaScript --&amp;gt;
    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Template Literals in JavaScript
&lt;/h3&gt;

&lt;p&gt;Template literals (&lt;strong&gt;also called template strings&lt;/strong&gt;) allow for &lt;strong&gt;easier string manipulation&lt;/strong&gt; using &lt;strong&gt;backticks (&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;/code&gt;)&lt;/strong&gt; instead of quotes.&lt;/p&gt;




&lt;h3&gt;
  
  
  Syntax:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;This is a template literal&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String Interpolation&lt;/strong&gt;&lt;br&gt;
Use ${} to insert variables or expressions directly into a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Alice";
let age = 25;

console.log(`My name is ${name} and I am ${age} years old.`);
// Output: My name is Alice and I am 25 years old.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Multi-line Strings&lt;/strong&gt;&lt;br&gt;
Template literals allow multi-line strings without needing \n.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let message = `This is line 1
This is line 2
This is line 3`;

console.log(message);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expression Evaluation&lt;/strong&gt;&lt;br&gt;
You can use expressions inside ${}.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 5, b = 10;

console.log(`The sum of ${a} and ${b} is ${a + b}.`);
// Output: The sum of 5 and 10 is 15.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript supports various &lt;strong&gt;operators&lt;/strong&gt; to perform operations on variables and values.&lt;/p&gt;




&lt;h4&gt;
  
  
  Arithmetic Operators
&lt;/h4&gt;

&lt;p&gt;Used to perform mathematical operations.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Addition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 + 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;8&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Subtraction&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10 - 4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;6&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Multiplication&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2 * 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Division&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10 / 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Modulus (Remainder)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10 % 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;**&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exponentiation (Power)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3 ** 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;9&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 + 2);  // 7
console.log(10 / 2); // 5
console.log(3 ** 2); // 9 (Exponentiation)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Assignment Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;Assignment operators are used to &lt;strong&gt;assign values to variables&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  List of Assignment Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Assigns &lt;code&gt;5&lt;/code&gt; to &lt;code&gt;x&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x += 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x + 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x -= 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x - 3&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x *= 4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x * 4&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x /= 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x / 5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x %= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x % 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  🔹 Example Usage
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 10;
x += 5;   // x = 15
x *= 2;   // x = 30
console.log(x); // Output: 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comparison Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;Comparison operators are used to &lt;strong&gt;compare values&lt;/strong&gt; and return a Boolean (&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;).&lt;/p&gt;




&lt;h4&gt;
  
  
  List of Comparison Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;==&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equal to (loose comparison)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 == "5"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;===&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Strictly equal (Type + Value)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 === "5"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 != "5"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!==&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Strictly not equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 !== "5"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10 &amp;gt; 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3 &amp;lt; 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Greater than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10 &amp;gt;= 10&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Less than or equal to&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3 &amp;lt;= 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Example Usage
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 == "5");  // true (loose comparison)
console.log(5 === "5"); // false (strict comparison)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;5 == '5'&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, the expression &lt;code&gt;5 == '5'&lt;/code&gt; evaluates to &lt;strong&gt;&lt;code&gt;true&lt;/code&gt;&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This happens because &lt;code&gt;==&lt;/code&gt; is the &lt;strong&gt;loose equality operator&lt;/strong&gt;, which &lt;strong&gt;performs type coercion&lt;/strong&gt; before comparing values.&lt;/p&gt;


&lt;h4&gt;
  
  
  Loose Equality (&lt;code&gt;==&lt;/code&gt;) vs. Strict Equality (&lt;code&gt;===&lt;/code&gt;)
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Expression&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;th&gt;Explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;5 == '5'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Loose equality (&lt;code&gt;==&lt;/code&gt;) &lt;strong&gt;converts types&lt;/strong&gt; before comparison. The string &lt;code&gt;'5'&lt;/code&gt; is converted to a number &lt;code&gt;5&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;5 === '5'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Strict equality (&lt;code&gt;===&lt;/code&gt;) &lt;strong&gt;does not perform type conversion&lt;/strong&gt;. Since &lt;code&gt;5&lt;/code&gt; (number) and &lt;code&gt;'5'&lt;/code&gt; (string) have different types, the result is &lt;code&gt;false&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example Usage
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 == '5');  // true (loose comparison with type coercion)
console.log(5 === '5'); // false (strict comparison without type coercion)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Logical Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;Logical operators are used to &lt;strong&gt;combine conditions&lt;/strong&gt; and return a Boolean (&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;).&lt;/p&gt;


&lt;h4&gt;
  
  
  List of Logical Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Logical AND&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true &amp;amp;&amp;amp; false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;`&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;`&lt;/td&gt;
&lt;td&gt;Logical OR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Logical NOT&lt;/td&gt;
&lt;td&gt;&lt;code&gt;!true&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example Usage
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(true &amp;amp;&amp;amp; false);  // false
console.log(true || false);  // true
console.log(!true);          // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Bitwise Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;Bitwise operators are used to perform &lt;strong&gt;binary calculations&lt;/strong&gt; by manipulating bits directly.&lt;/p&gt;


&lt;h4&gt;
  
  
  List of Bitwise Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;AND&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 &amp;amp; 1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;'&lt;/td&gt;
&lt;td&gt;'&lt;/td&gt;
&lt;td&gt;OR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;^&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;XOR&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 ^ 1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;~&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;NOT&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Left shift&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 &amp;lt;&amp;lt; 1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Right shift&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5 &amp;gt;&amp;gt; 1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h4&gt;
  
  
  Example Usage
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(5 &amp;amp; 1);  // 1  (AND operation)
console.log(5 | 1);  // 5  (OR operation)
console.log(5 ^ 1);  // 4  (XOR operation)
console.log(~5);     // -6 (NOT operation)
console.log(5 &amp;lt;&amp;lt; 1); // 10 (Left shift)
console.log(5 &amp;gt;&amp;gt; 1); // 2  (Right shift)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Ternary Operator in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;ternary operator&lt;/strong&gt; is a shorthand for &lt;code&gt;if...else&lt;/code&gt; statements.&lt;br&gt;&lt;br&gt;
It allows writing conditional logic in a &lt;strong&gt;compact&lt;/strong&gt; and &lt;strong&gt;readable&lt;/strong&gt; way.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;condition ? trueValue : falseValue;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Comparisons for Non-Numbers in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript allows &lt;strong&gt;comparisons&lt;/strong&gt; not only for numbers but also for &lt;strong&gt;strings, Booleans, and other data types&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
When comparing &lt;strong&gt;non-numeric values&lt;/strong&gt;, JavaScript applies &lt;strong&gt;type conversion rules&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Comparing Strings
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript compares &lt;strong&gt;strings&lt;/strong&gt; &lt;strong&gt;lexicographically&lt;/strong&gt; (alphabetical order) based on &lt;strong&gt;Unicode values&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Uppercase letters (&lt;code&gt;A-Z&lt;/code&gt;) come &lt;strong&gt;before&lt;/strong&gt; lowercase letters (&lt;code&gt;a-z&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("apple" &amp;gt; "banana");  // false (because "a" comes before "b")
console.log("Zoo" &amp;gt; "apple");     // false (uppercase "Z" comes before lowercase "a")
console.log("Hello" &amp;gt; "hello");   // false (uppercase "H" &amp;lt; lowercase "h")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Comparing Booleans in JavaScript
&lt;/h4&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;Booleans (&lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;) are converted to numbers&lt;/strong&gt; when used in comparisons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;false&lt;/code&gt; is treated as &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;true&lt;/code&gt; is treated as &lt;code&gt;1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(true &amp;gt; false);  // true (1 &amp;gt; 0)
console.log(false == 0);    // true (false → 0)
console.log(true == 1);     // true (true → 1)
console.log(false &amp;lt; true);  // true (0 &amp;lt; 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Comparing &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;JavaScript treats &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; &lt;strong&gt;differently&lt;/strong&gt; in comparisons.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(null == undefined);  // true (special case)
console.log(null === undefined); // false (strict comparison)
console.log(null &amp;gt; 0);           // false
console.log(null == 0);          // false
console.log(null &amp;gt;= 0);          // true (strange behavior)
console.log(undefined &amp;gt; 0);      // false
console.log(undefined == 0);     // false
console.log(undefined &amp;gt;= 0);     // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Comparing Objects in JavaScript
&lt;/h4&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;objects are not directly comparable&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
They are compared by &lt;strong&gt;reference&lt;/strong&gt;, not by value.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let obj1 = { name: "Alice" };
let obj2 = { name: "Alice" };

console.log(obj1 == obj2);  // false (different memory references)
console.log(obj1 === obj2); // false (even though they look the same)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Conditional Statements in JavaScript
&lt;/h3&gt;

&lt;p&gt;Conditional statements &lt;strong&gt;allow a program to make decisions&lt;/strong&gt; based on conditions.&lt;br&gt;&lt;br&gt;
JavaScript provides multiple ways to handle conditions.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;if&lt;/code&gt; Statement
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;if&lt;/code&gt; statement executes code &lt;strong&gt;only if a condition is true&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition) {
    // Code to execute if the condition is true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;if...else&lt;/code&gt; Statement in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;if...else&lt;/code&gt; statement&lt;/strong&gt; executes one block of code &lt;strong&gt;if the condition is true&lt;/strong&gt; and another block &lt;strong&gt;if it is false&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age = 16;

if (age &amp;gt;= 18) {
    console.log("You can vote.");
} else {
    console.log("You cannot vote.");
}
// Output: "You cannot vote."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;if...else if...else&lt;/code&gt; Statement in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;if...else if...else&lt;/code&gt; statement&lt;/strong&gt; is used when multiple conditions &lt;strong&gt;need to be checked sequentially&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
JavaScript &lt;strong&gt;evaluates each condition in order&lt;/strong&gt;, and the first condition that evaluates to &lt;code&gt;true&lt;/code&gt; gets executed.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let score = 85;

if (score &amp;gt;= 90) {
    console.log("Grade: A");
} else if (score &amp;gt;= 80) {
    console.log("Grade: B");
} else if (score &amp;gt;= 70) {
    console.log("Grade: C");
} else {
    console.log("Grade: F");
}
// Output: "Grade: B"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Ternary Operator (&lt;code&gt;? :&lt;/code&gt;) in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;ternary operator&lt;/strong&gt; is a &lt;strong&gt;shorter&lt;/strong&gt; and &lt;strong&gt;more concise&lt;/strong&gt; way to write an &lt;code&gt;if...else&lt;/code&gt; statement.&lt;br&gt;&lt;br&gt;
It is useful for simple conditions where you &lt;strong&gt;want to assign a value or execute a statement&lt;/strong&gt; based on a condition.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;condition ? trueValue : falseValue;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;switch&lt;/code&gt; Statement in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;switch&lt;/code&gt; statement&lt;/strong&gt; is used when a variable &lt;strong&gt;needs to be compared against multiple values&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It is often used as a cleaner alternative to multiple &lt;code&gt;if...else if...else&lt;/code&gt; statements.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;switch (expression) {
    case value1:
        // Code to execute if expression === value1
        break;
    case value2:
        // Code to execute if expression === value2
        break;
    default:
        // Code to execute if no cases match
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Nested &lt;code&gt;if...else&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;nested &lt;code&gt;if...else&lt;/code&gt; statement&lt;/strong&gt; is an &lt;code&gt;if...else&lt;/code&gt; inside another &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;else&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
It allows checking &lt;strong&gt;multiple conditions&lt;/strong&gt; in a hierarchical manner.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition1) {
    if (condition2) {
        // Code to execute if both conditions are true
    } else {
        // Code to execute if condition1 is true but condition2 is false
    }
} else {
    // Code to execute if condition1 is false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Logical Operators in JavaScript
&lt;/h3&gt;

&lt;p&gt;Logical operators are used to &lt;strong&gt;combine multiple conditions&lt;/strong&gt; and return a Boolean (&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;).&lt;br&gt;&lt;br&gt;
They are essential for making &lt;strong&gt;decisions&lt;/strong&gt; in conditional statements.&lt;/p&gt;
&lt;h4&gt;
  
  
  List of Logical Operators
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Logical AND&lt;/td&gt;
&lt;td&gt;&lt;code&gt;true &amp;amp;&amp;amp; false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;`&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;`&lt;/td&gt;
&lt;td&gt;Logical OR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Logical NOT&lt;/td&gt;
&lt;td&gt;&lt;code&gt;!true&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Example Usage
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(true &amp;amp;&amp;amp; false);  // false
console.log(true || false);  // true
console.log(!true);          // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Truthy and Falsy Values in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;every value is either "truthy" or "falsy"&lt;/strong&gt; when evaluated in a Boolean context.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Truthy values&lt;/strong&gt; behave like &lt;code&gt;true&lt;/code&gt; when used in a condition.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Falsy values&lt;/strong&gt; behave like &lt;code&gt;false&lt;/code&gt; when used in a condition.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Falsy Values
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;falsy&lt;/strong&gt; value is a value that evaluates to &lt;code&gt;false&lt;/code&gt; in a Boolean context.&lt;/p&gt;

&lt;p&gt;JavaScript has &lt;strong&gt;exactly 8 falsy values&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Falsy Value&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Boolean &lt;code&gt;false&lt;/code&gt; itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Number zero&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Negative zero&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;BigInt zero&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;""&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Empty string&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Absence of a value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Uninitialized variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NaN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Not-a-Number&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (0) {
    console.log("Truthy");
} else {
    console.log("Falsy");
}
// Output: "Falsy"

if ("") {
    console.log("Truthy");
} else {
    console.log("Falsy");
}
// Output: "Falsy"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Truthy Values in JavaScript
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;truthy value&lt;/strong&gt; is &lt;strong&gt;any value that is not falsy&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In JavaScript, &lt;strong&gt;all values are truthy unless they are in the list of falsy values&lt;/strong&gt; (&lt;code&gt;false&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;""&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;, etc.).&lt;/p&gt;
&lt;h4&gt;
  
  
  Common Truthy Values
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Truthy Value&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Non-empty strings&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello"&lt;/code&gt;, &lt;code&gt;"false"&lt;/code&gt;, &lt;code&gt;"0"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Numbers except &lt;code&gt;0&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;42&lt;/code&gt;, &lt;code&gt;-1&lt;/code&gt;, &lt;code&gt;3.14&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Non-empty arrays&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Non-empty objects&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;function() {}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Special values&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;" "&lt;/code&gt; (space), &lt;code&gt;"0"&lt;/code&gt; (string zero)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ("Hello") {
    console.log("Truthy");
} else {
    console.log("Falsy");
}
// Output: "Truthy"

if (42) {
    console.log("Truthy");
} else {
    console.log("Falsy");
}
// Output: "Truthy"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Alerts and Prompts in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript provides built-in methods to interact with users using &lt;strong&gt;alerts, prompts, and confirmations&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;alert()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;alert()&lt;/code&gt; method &lt;strong&gt;displays a pop-up message&lt;/strong&gt; to the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;alert("This is an alert!");&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;prompt()&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;prompt()&lt;/code&gt; method&lt;/strong&gt; is used to &lt;strong&gt;ask the user for input&lt;/strong&gt; via a pop-up dialog.&lt;br&gt;&lt;br&gt;
It returns the user input &lt;strong&gt;as a string&lt;/strong&gt;, or &lt;code&gt;null&lt;/code&gt; if the user clicks &lt;strong&gt;"Cancel"&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;let userInput = prompt("Enter your name:");&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;confirm()&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;confirm()&lt;/code&gt; method&lt;/strong&gt; displays a pop-up &lt;strong&gt;asking for user confirmation&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It returns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;true&lt;/code&gt; if the user clicks &lt;strong&gt;"OK"&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;false&lt;/code&gt; if the user clicks &lt;strong&gt;"Cancel"&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;let result = confirm("Are you sure?");&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  String Methods in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript provides many &lt;strong&gt;built-in methods&lt;/strong&gt; to manipulate and work with strings.&lt;br&gt;&lt;br&gt;
These methods help in &lt;strong&gt;searching, replacing, slicing, and modifying strings&lt;/strong&gt; efficiently.&lt;/p&gt;
&lt;h4&gt;
  
  
  Common String Methods
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.length&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns the string length&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"Hello".length&lt;/code&gt; → &lt;code&gt;5&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.toUpperCase()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Converts to &lt;strong&gt;uppercase&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello".toUpperCase()&lt;/code&gt; → &lt;code&gt;"HELLO"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.toLowerCase()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Converts to &lt;strong&gt;lowercase&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"HELLO".toLowerCase()&lt;/code&gt; → &lt;code&gt;"hello"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.charAt(index)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns character at &lt;strong&gt;index&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".charAt(4)&lt;/code&gt; → &lt;code&gt;"S"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.indexOf("str")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;strong&gt;first occurrence index&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello".indexOf("l")&lt;/code&gt; → &lt;code&gt;2&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.lastIndexOf("str")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;strong&gt;last occurrence index&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello".lastIndexOf("l")&lt;/code&gt; → &lt;code&gt;3&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.includes("str")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if string contains &lt;strong&gt;substring&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello".includes("he")&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.startsWith("str")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if string &lt;strong&gt;starts with&lt;/strong&gt; substring&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello".startsWith("he")&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.endsWith("str")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if string &lt;strong&gt;ends with&lt;/strong&gt; substring&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello".endsWith("lo")&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.slice(start, end)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Extracts substring &lt;strong&gt;(end not included)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".slice(0, 4)&lt;/code&gt; → &lt;code&gt;"Java"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.substring(start, end)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Similar to &lt;code&gt;.slice()&lt;/code&gt;, but can't accept negative indexes&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".substring(0, 4)&lt;/code&gt; → &lt;code&gt;"Java"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.substr(start, length)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Extracts substring of specific &lt;strong&gt;length&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".substr(4, 6)&lt;/code&gt; → &lt;code&gt;"Script"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.replace("old", "new")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replaces first match&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello world".replace("world", "JS")&lt;/code&gt; → &lt;code&gt;"hello JS"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.replaceAll("old", "new")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replaces &lt;strong&gt;all occurrences&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"apple apple".replaceAll("apple", "banana")&lt;/code&gt; → &lt;code&gt;"banana banana"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.split("delimiter")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Splits into an &lt;strong&gt;array&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"one,two,three".split(",")&lt;/code&gt; → &lt;code&gt;["one", "two", "three"]&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.trim()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes spaces from &lt;strong&gt;start &amp;amp; end&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"  hello  ".trim()&lt;/code&gt; → &lt;code&gt;"hello"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.repeat(n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Repeats string &lt;strong&gt;n times&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"Hi ".repeat(3)&lt;/code&gt; → &lt;code&gt;"Hi Hi Hi "&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Example Usage:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text = "JavaScript is fun!";

console.log(text.length);          // 18
console.log(text.toUpperCase());   // "JAVASCRIPT IS FUN!"
console.log(text.toLowerCase());   // "javascript is fun!"
console.log(text.charAt(0));       // "J"
console.log(text.includes("fun")); // true
console.log(text.startsWith("Java")); // true
console.log(text.endsWith("fun!"));  // true
console.log(text.slice(0, 10));     // "JavaScript"
console.log(text.replace("fun", "awesome")); // "JavaScript is awesome!"
console.log(text.split(" "));      // ["JavaScript", "is", "fun!"]
console.log("  hello  ".trim());   // "hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;trim()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;trim()&lt;/code&gt; method&lt;/strong&gt; removes &lt;strong&gt;whitespace&lt;/strong&gt; from both &lt;strong&gt;ends&lt;/strong&gt; of a string (&lt;strong&gt;start &amp;amp; end&lt;/strong&gt;), without affecting the spaces &lt;strong&gt;inside&lt;/strong&gt; the string.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string.trim();

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

&lt;/div&gt;

&lt;h3&gt;
  
  
  Strings are Immutable in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;strings are immutable&lt;/strong&gt;, meaning &lt;strong&gt;they cannot be changed after they are created&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Any operation that appears to modify a string &lt;strong&gt;actually returns a new string&lt;/strong&gt;, leaving the original string unchanged.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = "Hello";
str[0] = "J";  // Attempt to change the first letter
console.log(str);  
// Output: "Hello" (unchanged)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  String Methods with Arguments in JavaScript
&lt;/h3&gt;

&lt;p&gt;Many &lt;strong&gt;string methods&lt;/strong&gt; in JavaScript accept &lt;strong&gt;arguments&lt;/strong&gt;, allowing you to manipulate strings dynamically.&lt;/p&gt;
&lt;h4&gt;
  
  
  Common String Methods with Arguments
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.charAt(index)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns the character at a specific &lt;strong&gt;index&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".charAt(4)&lt;/code&gt; → &lt;code&gt;"S"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.slice(start, end)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Extracts a substring &lt;strong&gt;(end not included)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".slice(0, 4)&lt;/code&gt; → &lt;code&gt;"Java"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.substring(start, end)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Extracts substring &lt;strong&gt;(similar to &lt;code&gt;.slice()&lt;/code&gt;)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".substring(4, 10)&lt;/code&gt; → &lt;code&gt;"Script"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.substr(start, length)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Extracts a substring of &lt;strong&gt;specific length&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"JavaScript".substr(4, 6)&lt;/code&gt; → &lt;code&gt;"Script"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.replace("old", "new")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replaces the &lt;strong&gt;first occurrence&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"hello world".replace("world", "JS")&lt;/code&gt; → &lt;code&gt;"hello JS"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.replaceAll("old", "new")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replaces &lt;strong&gt;all occurrences&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"apple apple".replaceAll("apple", "banana")&lt;/code&gt; → &lt;code&gt;"banana banana"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.split("delimiter")&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Splits into an &lt;strong&gt;array&lt;/strong&gt; based on a delimiter&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"one,two,three".split(",")&lt;/code&gt; → &lt;code&gt;["one", "two", "three"]&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.repeat(n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Repeats the string &lt;strong&gt;n times&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;"Hi ".repeat(3)&lt;/code&gt; → &lt;code&gt;"Hi Hi Hi "&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  &lt;code&gt;indexOf()&lt;/code&gt; Method in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;indexOf()&lt;/code&gt; method&lt;/strong&gt; returns the &lt;strong&gt;first occurrence index&lt;/strong&gt; of a specified substring within a string.&lt;br&gt;&lt;br&gt;
If the substring &lt;strong&gt;is not found&lt;/strong&gt;, it returns &lt;code&gt;-1&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;string.indexOf(searchValue, startIndex);&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Method Chaining in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Method chaining&lt;/strong&gt; is a technique in JavaScript where &lt;strong&gt;multiple methods&lt;/strong&gt; are called on an object &lt;strong&gt;in a single statement&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This makes the code &lt;strong&gt;cleaner and more readable&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text = "  JavaScript Method Chaining  ";

let result = text.trim().toUpperCase().replace("CHAINING", "MAGIC");

console.log(result);
// Output: "JAVASCRIPT METHOD MAGIC"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;slice()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;slice()&lt;/code&gt; method&lt;/strong&gt; extracts a portion of a string and returns &lt;strong&gt;a new string&lt;/strong&gt; &lt;strong&gt;without modifying&lt;/strong&gt; the original string.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;string.slice(startIndex, endIndex);&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;replace()&lt;/code&gt; Method
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;replace()&lt;/code&gt; method&lt;/strong&gt; searches for a specified substring and replaces it with a new value.&lt;br&gt;&lt;br&gt;
By default, it &lt;strong&gt;only replaces the first occurrence&lt;/strong&gt; unless you use &lt;code&gt;replaceAll()&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;string.replace(searchValue, newValue);&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;repeat()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;repeat()&lt;/code&gt; method&lt;/strong&gt; creates a &lt;strong&gt;new string&lt;/strong&gt; by repeating the original string &lt;strong&gt;&lt;code&gt;n&lt;/code&gt; times&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;string.repeat(n);&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Array Data Structure in JavaScript
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;array&lt;/strong&gt; in JavaScript is a data structure that allows &lt;strong&gt;storing multiple values&lt;/strong&gt; in a &lt;strong&gt;single variable&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It can hold elements of &lt;strong&gt;different data types&lt;/strong&gt;, including numbers, strings, objects, and even other arrays.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating an Array
&lt;/h4&gt;
&lt;h4&gt;
  
  
  Using Square Brackets &lt;code&gt;[]&lt;/code&gt; (Most Common)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits);
// Output: ["Apple", "Banana", "Cherry"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Creating an Array Using &lt;code&gt;new Array()&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;JavaScript allows you to create arrays using the &lt;strong&gt;&lt;code&gt;new Array()&lt;/code&gt;&lt;/strong&gt; constructor.&lt;br&gt;&lt;br&gt;
This method is &lt;strong&gt;less commonly used&lt;/strong&gt; than square brackets &lt;code&gt;[]&lt;/code&gt;, but it's useful in certain cases.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;let arrayName = new Array(element1, element2, ...);&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Mixed Arrays in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;mixed array&lt;/strong&gt; in JavaScript is an array that contains &lt;strong&gt;multiple data types&lt;/strong&gt;, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Numbers&lt;/li&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Booleans&lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Creating a Mixed Array
&lt;/h4&gt;

&lt;p&gt;JavaScript &lt;strong&gt;allows arrays to hold multiple data types&lt;/strong&gt; in the same array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let mixedArray = [42, "Hello", true, { name: "Alice" }, [1, 2, 3], function() { return "Hi!"; }];

console.log(mixedArray);
// Output: [42, "Hello", true, {name: "Alice"}, [1, 2, 3], function]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Accessing Characters in a String Inside an Array
&lt;/h3&gt;

&lt;p&gt;In JavaScript, when you store a &lt;strong&gt;string inside an array&lt;/strong&gt;, you can &lt;strong&gt;access individual characters&lt;/strong&gt; using &lt;strong&gt;indexing&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = ["bhupesh", 1, 2];

console.log(arr[0][0]); // "b"
console.log(arr[0][1]); // "h"
console.log(arr[0][2]); // "u"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Arrays are Mutable in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;arrays are mutable&lt;/strong&gt;, meaning their elements &lt;strong&gt;can be modified, added, or removed&lt;/strong&gt; without changing their reference in memory.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: Modifying an Array
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1, 2, 3, 4];

numbers[1] = 99;  // Changing the value at index 1

console.log(numbers);
// Output: [1, 99, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Array Methods in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript provides various &lt;strong&gt;built-in array methods&lt;/strong&gt; to manipulate and process arrays efficiently.&lt;/p&gt;

&lt;h4&gt;
  
  
  Common Array Methods
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.push(value)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Adds an element &lt;strong&gt;to the end&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.push("Mango")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.pop()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes &lt;strong&gt;the last element&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.pop()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.unshift(value)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Adds an element &lt;strong&gt;to the beginning&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.unshift("First")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.shift()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes &lt;strong&gt;the first element&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.shift()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.indexOf(value)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;strong&gt;index of value&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.indexOf("Apple")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.includes(value)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Checks if array &lt;strong&gt;contains value&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;arr.includes("Banana")&lt;/code&gt; → &lt;code&gt;true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.slice(start, end)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns a &lt;strong&gt;portion of an array&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.slice(1, 3)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.splice(start, deleteCount, item)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Removes or adds elements&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.splice(2, 1, "New")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.reverse()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reverses the array&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.reverse()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.sort()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sorts array &lt;strong&gt;alphabetically&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.sort()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.concat(arr2)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Combines two arrays&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.concat(arr2)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.join(separator)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Converts array &lt;strong&gt;to string&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.join(", ")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.map(fn)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Creates a &lt;strong&gt;new array&lt;/strong&gt; by applying function&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.map(x =&amp;gt; x * 2)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.filter(fn)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns elements that match a &lt;strong&gt;condition&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.filter(x =&amp;gt; x &amp;gt; 5)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.reduce(fn, initialValue)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reduces array to &lt;strong&gt;a single value&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.reduce((sum, num) =&amp;gt; sum + num, 0)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.forEach(fn)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Iterates over each element&lt;/td&gt;
&lt;td&gt;&lt;code&gt;arr.forEach(x =&amp;gt; console.log(x))&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Example Usage:
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Adding &amp;amp; Removing Elements
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let fruits = ["Apple", "Banana", "Cherry"];

fruits.push("Mango");  // Adds to the end
fruits.unshift("Mango"); // Adds to the beginning

console.log(fruits);
// Output: ["Mango", "Apple", "Banana", "Cherry"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Extracting a Portion of an Array (&lt;code&gt;slice()&lt;/code&gt;)
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;slice()&lt;/code&gt; method&lt;/strong&gt; extracts a portion of an array &lt;strong&gt;without modifying&lt;/strong&gt; the original array.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let colors = ["Red", "Green", "Blue", "Yellow"];

let slicedColors = colors.slice(1, 3);
console.log(slicedColors);
// Output: ["Green", "Blue"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Modifying an Array Using &lt;code&gt;splice()&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;splice()&lt;/code&gt; method&lt;/strong&gt; allows you to &lt;strong&gt;add, remove, or replace&lt;/strong&gt; elements in an array by modifying the original array.&lt;/p&gt;

&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.splice(startIndex, deleteCount, item1, item2, ...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Transforming an Array Using &lt;code&gt;map()&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;map()&lt;/code&gt; method&lt;/strong&gt; creates a &lt;strong&gt;new array&lt;/strong&gt; by applying a function to &lt;strong&gt;each element&lt;/strong&gt; of an existing array.&lt;br&gt;&lt;br&gt;
It &lt;strong&gt;does not modify&lt;/strong&gt; the original array.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.map(function(element, index, array) {
    return modifiedElement;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Filtering an Array (&lt;code&gt;filter()&lt;/code&gt;)
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;filter()&lt;/code&gt; method&lt;/strong&gt; returns a &lt;strong&gt;new array&lt;/strong&gt; containing only elements that match a specified condition.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.filter(function(element, index, array) {
    return condition;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Reducing an Array Using &lt;code&gt;reduce()&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;reduce()&lt;/code&gt; method&lt;/strong&gt; reduces an array to &lt;strong&gt;a single value&lt;/strong&gt; by applying a function.&lt;br&gt;&lt;br&gt;
It is commonly used for &lt;strong&gt;summation, finding maximum/minimum values, and more&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.reduce(function(accumulator, element, index, array) {
    return newAccumulator;
}, initialValue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Issue with Sorting Numbers Using &lt;code&gt;sort()&lt;/code&gt; in JavaScript
&lt;/h4&gt;

&lt;p&gt;By default, the &lt;strong&gt;&lt;code&gt;sort()&lt;/code&gt; method&lt;/strong&gt; in JavaScript &lt;strong&gt;treats numbers as strings&lt;/strong&gt;,&lt;br&gt;&lt;br&gt;
leading to &lt;strong&gt;incorrect sorting results&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Incorrect Sorting (Default Behavior)
&lt;/h4&gt;
&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [10, 5, 40, 25, 1];

console.log(numbers.sort());
// Output: [1, 10, 25, 40, 5] (Incorrect)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The sort() method converts numbers to strings before sorting.&lt;/li&gt;
&lt;li&gt;When sorting strings, JavaScript compares character by character (lexicographical order).&lt;/li&gt;
&lt;li&gt;Since "1" comes before "5", "10" is placed before "5".&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Array References in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;arrays are reference types&lt;/strong&gt;, meaning they are &lt;strong&gt;stored by reference&lt;/strong&gt; rather than by value.&lt;br&gt;&lt;br&gt;
This affects how arrays are assigned, compared, and modified.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example: Arrays Are Stored by Reference
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr1 = [1, 2, 3];
let arr2 = arr1;  // Both variables point to the same array

arr2.push(4);

console.log(arr1); // Output: [1, 2, 3, 4]
console.log(arr2); // Output: [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Constant Arrays in JavaScript (&lt;code&gt;const&lt;/code&gt; Arrays)
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;arrays declared with &lt;code&gt;const&lt;/code&gt; are not immutable&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
You &lt;strong&gt;cannot reassign&lt;/strong&gt; a &lt;code&gt;const&lt;/code&gt; array, but you &lt;strong&gt;can modify its contents&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Declaring a Constant Array
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4];

console.log(numbers); 
// Output: [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Nested Arrays in JavaScript (Multi-Dimensional Arrays)
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;nested array&lt;/strong&gt; (or &lt;strong&gt;multi-dimensional array&lt;/strong&gt;) is an array that &lt;strong&gt;contains other arrays&lt;/strong&gt; as elements.&lt;br&gt;&lt;br&gt;
These are useful for representing &lt;strong&gt;grids, tables, or hierarchical data structures&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating a Nested Array
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];

console.log(matrix);
// Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;for&lt;/code&gt; Loops in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/strong&gt; in JavaScript is used to &lt;strong&gt;execute a block of code multiple times&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It is commonly used for iterating over arrays, objects, and performing repetitive tasks.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (initialization; condition; iteration) {
    // Code to execute
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Nested &lt;code&gt;for&lt;/code&gt; Loops in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;nested &lt;code&gt;for&lt;/code&gt; loop&lt;/strong&gt; is a loop inside another loop.&lt;br&gt;&lt;br&gt;
It is commonly used for working with &lt;strong&gt;multi-dimensional arrays, tables, and grids&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (initialization; condition; iteration) {
    for (initialization; condition; iteration) {
        // Code to execute
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;while&lt;/code&gt; Loops in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;&lt;code&gt;while&lt;/code&gt; loop&lt;/strong&gt; in JavaScript &lt;strong&gt;executes a block of code repeatedly&lt;/strong&gt; &lt;strong&gt;as long as the condition remains &lt;code&gt;true&lt;/code&gt;&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It is useful when the number of iterations is &lt;strong&gt;not known beforehand&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (condition) {
    // Code to execute
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;break&lt;/code&gt; Keyword in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;break&lt;/code&gt; keyword&lt;/strong&gt; in JavaScript is used to &lt;strong&gt;exit a loop or switch statement prematurely&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It &lt;strong&gt;immediately stops execution&lt;/strong&gt; and exits the loop.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (initialization; condition; iteration) {
    if (exitCondition) {
        break;  // Exit the loop
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Looping Through Arrays in JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript provides multiple ways to &lt;strong&gt;iterate over arrays&lt;/strong&gt; using different loops.&lt;br&gt;&lt;br&gt;
Each method has its own use case, performance, and readability.&lt;/p&gt;
&lt;h4&gt;
  
  
  Using a &lt;code&gt;for&lt;/code&gt; Loop (Traditional Way)
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/strong&gt; gives full control over &lt;strong&gt;iteration&lt;/strong&gt; using an index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let fruits = ["Apple", "Banana", "Cherry"];

for (let i = 0; i &amp;lt; fruits.length; i++) {
    console.log(fruits[i]);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;/* Output:&lt;br&gt;
Apple&lt;br&gt;
Banana&lt;br&gt;
Cherry&lt;br&gt;
*/&lt;/p&gt;
&lt;h3&gt;
  
  
  Looping Through Nested Arrays in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;nested array&lt;/strong&gt; (or multi-dimensional array) is an array that &lt;strong&gt;contains other arrays as elements&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
To iterate over nested arrays, you need &lt;strong&gt;nested loops&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Example: Looping Through a 2D Array Using a &lt;code&gt;for&lt;/code&gt; Loop
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];

for (let i = 0; i &amp;lt; matrix.length; i++) {
    for (let j = 0; j &amp;lt; matrix[i].length; j++) {
        console.log(matrix[i][j]);
    }
}

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

&lt;/div&gt;


&lt;p&gt;/* Output:&lt;br&gt;
1&lt;br&gt;
2&lt;br&gt;
3&lt;br&gt;
4&lt;br&gt;
5&lt;br&gt;
6&lt;br&gt;
7&lt;br&gt;
8&lt;br&gt;
9&lt;br&gt;
*/&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;for...of&lt;/code&gt; Loop in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;for...of&lt;/code&gt; loop&lt;/strong&gt; in JavaScript is used to &lt;strong&gt;iterate over iterable objects&lt;/strong&gt; like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Arrays&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strings&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maps&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sets&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NodeLists&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Basic Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let variable of iterable) {
    // Code to execute
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Nested &lt;code&gt;for...of&lt;/code&gt; Loop in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;nested &lt;code&gt;for...of&lt;/code&gt; loop&lt;/strong&gt; is used to iterate over &lt;strong&gt;multi-dimensional arrays or nested structures&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It is commonly used when working with &lt;strong&gt;nested arrays (2D arrays), objects inside arrays, or matrices&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let outerElement of outerIterable) {
    for (let innerElement of innerIterable) {
        // Code to execute
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Object Literals in JavaScript
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;object literal&lt;/strong&gt; in JavaScript is a way to create an object using &lt;strong&gt;key-value pairs&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It is the most common and convenient method for &lt;strong&gt;defining objects&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating an Object Literal
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Bhupesh",
    age: 25,
    city: "Waterloo"
};

console.log(person);
// Output: { name: "Bhupesh", age: 25, city: "Waterloo" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Getting Values from an Object in JavaScript
&lt;/h3&gt;

&lt;p&gt;There are multiple ways to &lt;strong&gt;retrieve values&lt;/strong&gt; from an object in JavaScript.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Using Dot Notation (&lt;code&gt;.&lt;/code&gt;)
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Dot notation&lt;/strong&gt; is the simplest way to access object properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Alice",
    age: 25,
    city: "New York"
};

console.log(person.name);  // Output: "Alice"
console.log(person.age);   // Output: 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Using Bracket Notation ([])
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(person["city"]); // Output: "New York"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using Object.values()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let car = { brand: "Toyota", model: "Corolla", year: 2023 };

console.log(Object.values(car));
// Output: ["Toyota", "Corolla", 2023]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Looping Through an Object (for...in)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let key in person) {
    console.log(person[key]);
}

/* Output:
Alice
25
New York
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding and Updating Values in JavaScript Objects
&lt;/h3&gt;

&lt;p&gt;In JavaScript, you can &lt;strong&gt;add new properties&lt;/strong&gt; or &lt;strong&gt;update existing values&lt;/strong&gt; in an object using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dot notation (&lt;code&gt;.&lt;/code&gt;)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bracket notation (&lt;code&gt;[]&lt;/code&gt;)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1. Adding a New Property
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Using Dot Notation:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = { name: "Alice", age: 25 };

person.city = "New York"; // Adds a new property

console.log(person);
// Output: { name: "Alice", age: 25, city: "New York" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using Bracket Notation:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person["country"] = "USA"; // Adds a new property

console.log(person);
// Output: { name: "Alice", age: 25, city: "New York", country: "USA" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Updating an Existing Property
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person.age = 30; // Updating an existing value
console.log(person.age); 
// Output: 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person["name"] = "Bob";
console.log(person.name);
// Output: "Bob"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Adding or Updating Nested Properties
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let student = {
    name: "John",
    grades: { math: 80, science: 90 }
};

// Updating an existing nested value
student.grades.math = 95;

// Adding a new subject
student.grades.english = 85;

console.log(student);

/* Output:
{
    name: "John",
    grades: { math: 95, science: 90, english: 85 }
}
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Using Object.assign() to Add/Update Multiple Values
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.assign(person, { age: 35, gender: "Female" });

console.log(person);
// Output: { name: "Bob", age: 35, city: "New York", country: "USA", gender: "Female" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Using the Spread Operator (...) to Add/Update
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let updatedPerson = { ...person, age: 40, hobby: "Reading" };

console.log(updatedPerson);
// Output: { name: "Bob", age: 40, city: "New York", country: "USA", gender: "Female", hobby: "Reading" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Nested Objects in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;nested object&lt;/strong&gt; is an object &lt;strong&gt;inside another object&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This is useful for &lt;strong&gt;representing hierarchical data&lt;/strong&gt; such as &lt;strong&gt;users, products, and configurations&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating a Nested Object
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Alice",
    age: 25,
    address: {
        street: "123 Main St",
        city: "New York",
        country: "USA"
    }
};

console.log(person);
/* Output:
{
  name: "Alice",
  age: 25,
  address: {
    street: "123 Main St",
    city: "New York",
    country: "USA"
  }
}
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Array of Objects in JavaScript
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;array of objects&lt;/strong&gt; is a collection where &lt;strong&gt;each element is an object&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This is commonly used for handling &lt;strong&gt;lists of users, products, employees, etc.&lt;/strong&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating an Array of Objects
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let users = [
    { name: "Alice", age: 25, city: "New York" },
    { name: "Bob", age: 30, city: "Los Angeles" },
    { name: "Charlie", age: 22, city: "Chicago" }
];

console.log(users);
/* Output:
[
  { name: "Alice", age: 25, city: "New York" },
  { name: "Bob", age: 30, city: "Los Angeles" },
  { name: "Charlie", age: 22, city: "Chicago" }
]
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Math Object in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Math object&lt;/strong&gt; in JavaScript provides &lt;strong&gt;built-in methods&lt;/strong&gt; for performing mathematical operations.&lt;br&gt;&lt;br&gt;
It includes methods for &lt;strong&gt;rounding numbers, generating random values, finding min/max, and more&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Math Properties (Constants)
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Property&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Math.PI&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The value of &lt;strong&gt;π (pi)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3.141592653589793&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Math.E&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Euler’s number&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2.718&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Math.LN2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Natural logarithm of 2&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0.693&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Math.LN10&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Natural logarithm of 10&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2.302&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Math.PI);  // 3.141592653589793
console.log(Math.E);   // 2.718281828459045
console.log(Math.round(4.6));  // 5

console.log(Math.floor(4.9));  // 4  Round off to nearest, smallest integer value

console.log(Math.ceil(4.1));   // 5  Round off to nearest, largest integer value

console.log(Math.trunc(4.9));  // 4
console.log(Math.random());  
// Output: Random decimal between 0 and 1
console.log(Math.min(5, 3, 9, 1)); // 1
console.log(Math.max(5, 3, 9, 1)); // 9
console.log(Math.pow(2, 3));   // 8
console.log(Math.sqrt(25));    // 5
console.log(Math.cbrt(27));    // 3
console.log(Math.sin(Math.PI / 2)); // 1
console.log(Math.cos(0));           // 1
console.log(Math.tan(Math.PI / 4)); // 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

console.log(getRandomInt(1, 10)); 
// Output: Random integer between 1 and 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Functions in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;function&lt;/strong&gt; in JavaScript is a &lt;strong&gt;block of reusable code&lt;/strong&gt; that performs a specific task.&lt;br&gt;&lt;br&gt;
Functions help make code &lt;strong&gt;modular, reusable, and organized&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Declaring a Function
&lt;/h4&gt;
&lt;h4&gt;
  
  
  1*&lt;em&gt;Function Declaration (Named Function)&lt;/em&gt;*
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet() {
    console.log("Hello, world!");
}

greet(); 
// Output: Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Function Expression (Anonymous Function)&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = function() {
    console.log("Hello, world!");
};

greet();
// Output: Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Arrow Function (=&amp;gt;) (Shorter Syntax)&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = () =&amp;gt; {
    console.log("Hello, world!");
};

greet();
// Output: Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Function Parameters and Arguments
&lt;/h3&gt;
&lt;h4&gt;
  
  
  4. &lt;strong&gt;Function with Parameters&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name) {
    console.log(`Hello, ${name}!`);
}

greet("Alice");
// Output: Hello, Alice!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  5. &lt;strong&gt;Function with Default Parameters&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name = "Guest") {
    console.log(`Hello, ${name}!`);
}

greet();       
// Output: Hello, Guest!
greet("Bob");  
// Output: Hello, Bob!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Returning Values from Functions
&lt;/h3&gt;
&lt;h4&gt;
  
  
  6. &lt;strong&gt;Function with Return Statement&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function add(a, b) {
    return a + b;
}

let sum = add(5, 3);
console.log(sum);  
// Output: 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Function Scope
&lt;/h3&gt;
&lt;h4&gt;
  
  
  7. &lt;strong&gt;Local Scope (Inside Function)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;A locally scoped variable is declared inside a function and only accessible within that function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function testScope() {
    let localVar = "I am local";
    console.log(localVar);
}

testScope();
// Output: I am local

console.log(localVar); 
// Error: localVar is not defined (only exists inside function)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  8. &lt;strong&gt;Global Scope (Outside Function)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;globally scoped&lt;/strong&gt; variable can be accessed &lt;strong&gt;anywhere in the script&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let globalVar = "I am global";

function testScope() {
    console.log(globalVar);
}

testScope();
// Output: I am global
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  9. &lt;strong&gt;Block Scope {} (Using let &amp;amp; const)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Block scope means variables declared inside {} cannot be accessed outside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true) {
    let blockVar = "I am block scoped";
    console.log(blockVar); // Accessible inside block
}

console.log(blockVar); // Error: blockVar is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  10. &lt;strong&gt;Scope with var vs let &amp;amp; const&lt;/strong&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  var is NOT block-scoped:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true) {
    var testVar = "I am using var";
}
console.log(testVar); // ✅ Accessible outside the block (not safe)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  let and const are block-scoped:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true) {
    let testLet = "I am using let";
}
console.log(testLet); // ❌ Error: testLet is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  11. &lt;strong&gt;Lexical Scope (Nested Functions)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;A nested function can access variables from its parent function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
    let outerVar = "I am outer";

    function inner() {
        console.log(outerVar); // ✅ Accessible (lexical scope)
    }

    inner();
}

outer();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Hoisting in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Hoisting&lt;/strong&gt; is JavaScript’s behavior of &lt;strong&gt;moving variable and function declarations to the top&lt;/strong&gt; of their scope &lt;strong&gt;before execution&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This means you can use variables and functions &lt;strong&gt;before declaring them&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Function Hoisting (Works with Function Declarations)
&lt;/h4&gt;

&lt;p&gt;Function &lt;strong&gt;declarations&lt;/strong&gt; are &lt;strong&gt;hoisted entirely&lt;/strong&gt;, meaning you can call them before defining them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;greet(); // ✅ No Error

function greet() {
    console.log("Hello, world!");
}

/* Output:
Hello, world!
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Function Expressions in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;function expression&lt;/strong&gt; in JavaScript is a way to &lt;strong&gt;define a function inside a variable&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Unlike &lt;strong&gt;function declarations&lt;/strong&gt;, function expressions &lt;strong&gt;are not hoisted&lt;/strong&gt; and must be defined before use.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Basic Function Expression
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = function() {
    console.log("Hello, world!");
};

greet();  
// Output: Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. Named vs. Anonymous Function Expressions
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = function() {
    console.log("Hello!");
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = function greetFunction() {
    console.log("Hello!");
};

greet();  
// Output: Hello!

console.log(typeof greetFunction);  
// ❌ ReferenceError: greetFunction is not defined (not available outside)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  3. Function Expressions as Arguments (Callback Functions)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(function() {
    console.log("Executed after 2 seconds!");
}, 2000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  4. Assigning a Function Expression Dynamically
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let operation;

if (true) {
    operation = function(a, b) {
        return a + b;
    };
} else {
    operation = function(a, b) {
        return a - b;
    };
}

console.log(operation(5, 3));  
// Output: 8 (since the first function was assigned)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  5. Arrow Functions (=&amp;gt;) - A Shorter Alternative
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = () =&amp;gt; {
    console.log("Hello!");
};

greet();  
// Output: Hello!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Higher-Order Functions in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;higher-order function (HOF)&lt;/strong&gt; is a function that &lt;strong&gt;takes another function as an argument&lt;/strong&gt; or &lt;strong&gt;returns a function&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
These functions make JavaScript more &lt;strong&gt;powerful, reusable, and modular&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Functions as Arguments
&lt;/h4&gt;

&lt;p&gt;A higher-order function &lt;strong&gt;accepts another function&lt;/strong&gt; as a &lt;strong&gt;callback&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example: &lt;code&gt;setTimeout()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(function() {
    console.log("Executed after 2 seconds!");
}, 2000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Functions Returning Functions
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function multiplier(factor) {
    return function(number) {
        return number * factor;
    };
}

const double = multiplier(2);
console.log(double(5));  // Output: 10

const triple = multiplier(3);
console.log(triple(5));  // Output: 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Methods in JavaScript
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;method&lt;/strong&gt; in JavaScript is a function that is &lt;strong&gt;stored as a property inside an object&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Methods allow objects to have &lt;strong&gt;behavior&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Creating a Method in an Object
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Alice",
    age: 25,
    greet: function() {
        console.log(`Hello, my name is ${this.name}`);
    }
};

person.greet();
// Output: "Hello, my name is Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. Using this in Methods
&lt;/h4&gt;

&lt;p&gt;this refers to the object that calls the method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let car = {
    brand: "Toyota",
    model: "Corolla",
    getDetails: function() {
        return `${this.brand} ${this.model}`;
    }
};

console.log(car.getDetails());
// Output: "Toyota Corolla"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using ES6 Method Shorthand
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user = {
    name: "John",
    greet() {  // Shorter syntax
        return `Hello, ${this.name}`;
    }
};

console.log(user.greet());
// Output: "Hello, John"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Adding a Method to an Object Dynamically
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = { name: "Bob" };

person.sayHi = function() {
    return `Hi, I'm ${this.name}!`;
};

console.log(person.sayHi());
// Output: "Hi, I'm Bob!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Object Methods: Object.keys(), Object.values(), Object.entries()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let student = { name: "Alice", age: 22 };

console.log(Object.keys(student));
// Output: ["name", "age"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Object.values(student));
// Output: ["Alice", 22]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(Object.entries(student));
/* Output:
[
  ["name", "Alice"],
  ["age", 22]
]
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Method Borrowing (call, apply, bind)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user1 = { name: "Alice" };
let user2 = { name: "Bob" };

function greet() {
    console.log(`Hello, ${this.name}`);
}

greet.call(user1); // Output: "Hello, Alice"
greet.call(user2); // Output: "Hello, Bob"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;this&lt;/code&gt; Keyword in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;this&lt;/code&gt; keyword&lt;/strong&gt; in JavaScript refers to &lt;strong&gt;the object that is executing the current function&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Its value depends on &lt;strong&gt;how and where&lt;/strong&gt; the function is called.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. &lt;code&gt;this&lt;/code&gt; in the Global Context 🌍
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(this); 
// Output: Window object (in browsers)
// Output: {} (in Node.js)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. this Inside an Object Method
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Alice",
    greet: function() {
        console.log(`Hello, my name is ${this.name}`);
    }
};

person.greet();  
// Output: "Hello, my name is Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  3. this in a Regular Function (Undefined in strict mode)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function showThis() {
    console.log(this);
}

showThis();
// Output: `window` (in non-strict mode)
// Output: `undefined` (in strict mode)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  4. this Inside an Arrow Function
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user = {
    name: "Bob",
    greet: () =&amp;gt; {
        console.log(`Hello, ${this.name}`);
    }
};

user.greet();
// Output: "Hello, undefined"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  5. this in an Event Listener
&lt;/h4&gt;

&lt;p&gt;In event listeners, this refers to the HTML element that triggered the event.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let button = document.createElement("button");
button.innerText = "Click Me";

button.addEventListener("click", function() {
    console.log(this);  // Refers to the button element
});

document.body.appendChild(button);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. this in a Constructor Function
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Person(name) {
    this.name = name;
}

let person1 = new Person("Charlie");

console.log(person1.name);  
// Output: "Charlie"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  7. this in Classes (ES6)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
    constructor(brand) {
        this.brand = brand;
    }

    showBrand() {
        console.log(`This car is a ${this.brand}`);
    }
}

let myCar = new Car("Toyota");
myCar.showBrand();  
// Output: "This car is a Toyota"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  8. Controlling this with call(), apply(), and bind()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet() {
    console.log(`Hello, ${this.name}`);
}

let user1 = { name: "Alice" };
greet.call(user1);  
// Output: "Hello, Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;greet.apply(user1);  
// Output: "Hello, Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let newGreet = greet.bind(user1);
newGreet();  
// Output: "Hello, Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;try...catch&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;try...catch&lt;/code&gt; statement&lt;/strong&gt; in JavaScript is used for &lt;strong&gt;handling errors&lt;/strong&gt; gracefully.&lt;br&gt;&lt;br&gt;
It allows code to &lt;strong&gt;continue executing&lt;/strong&gt; even if an error occurs.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
    // Code that may throw an error
} catch (error) {
    // Code to handle the error
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. Using finally (Always Executes)
&lt;/h4&gt;

&lt;p&gt;The finally block runs regardless of whether an error occurs or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
    let num = 10;
    console.log(num.toUpperCase()); // ❌ TypeError
} catch (error) {
    console.log("Error caught:", error.message);
} finally {
    console.log("This runs no matter what!");
}

/* Output:
Error caught: num.toUpperCase is not a function
This runs no matter what!
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Throwing Custom Errors (throw)
&lt;/h4&gt;

&lt;p&gt;You can manually throw errors using the throw keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function checkAge(age) {
    if (age &amp;lt; 18) {
        throw new Error("You must be at least 18 years old.");
    }
    return "Access granted.";
}

try {
    console.log(checkAge(16)); // ❌ Throws an error
} catch (error) {
    console.log("Error:", error.message);
}

/* Output:
Error: You must be at least 18 years old.
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Nested try...catch
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
    try {
        throw new Error("Something went wrong!");
    } catch (innerError) {
        console.log("Inner catch:", innerError.message);
        throw new Error("Outer error triggered.");
    }
} catch (outerError) {
    console.log("Outer catch:", outerError.message);
}

/* Output:
Inner catch: Something went wrong!
Outer catch: Outer error triggered.
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Arrow Functions in JavaScript (&lt;code&gt;=&amp;gt;&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;arrow function&lt;/strong&gt; (&lt;code&gt;=&amp;gt;&lt;/code&gt;) is a &lt;strong&gt;shorter and cleaner way&lt;/strong&gt; to write functions in JavaScript.&lt;br&gt;&lt;br&gt;
It simplifies function expressions and has &lt;strong&gt;no &lt;code&gt;this&lt;/code&gt; binding&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Basic Arrow Function Syntax
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = () =&amp;gt; {
    console.log("Hello, world!");
};

greet();
// Output: "Hello, world!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Arrow Function with Parameters
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = (name) =&amp;gt; {
    return `Hello, ${name}!`;
};

console.log(greet("Alice"));
// Output: "Hello, Alice!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Implicit Return (Shorter Syntax)
&lt;/h4&gt;

&lt;p&gt;When there is only one expression, the return keyword can be omitted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const add = (a, b) =&amp;gt; a + b;

console.log(add(5, 3)); 
// Output: 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Arrow Function Without Parentheses (One Parameter)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const square = x =&amp;gt; x * x;

console.log(square(4));  
// Output: 16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Arrow Function in forEach()
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1, 2, 3];

numbers.forEach(num =&amp;gt; console.log(num * 2));

/* Output:
2
4
6
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Arrow Functions and this (Does NOT Work Like Regular Functions)
&lt;/h4&gt;

&lt;p&gt;Arrow functions do not have their own this.&lt;br&gt;
They inherit this from the surrounding scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Alice",
    greet: function() {
        setTimeout(() =&amp;gt; {
            console.log(`Hello, my name is ${this.name}`);
        }, 1000);
    }
};

person.greet();
// Output (after 1 second): "Hello, my name is Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Arrow Functions Should NOT Be Used As Methods
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Alice",
    greet: () =&amp;gt; {
        console.log(`Hello, my name is ${this.name}`);
    }
};

person.greet();
// Output: "Hello, my name is undefined"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;setTimeout()&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;setTimeout()&lt;/code&gt; function&lt;/strong&gt; in JavaScript is used to &lt;strong&gt;execute a function after a specified delay&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(function, delay);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Delayed Execution
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(() =&amp;gt; {
    console.log("This message appears after 2 seconds!");
}, 2000);

/* Output (after 2 seconds):
This message appears after 2 seconds!
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;setInterval()&lt;/code&gt; in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;setInterval()&lt;/code&gt; function&lt;/strong&gt; in JavaScript is used to &lt;strong&gt;execute a function repeatedly&lt;/strong&gt; at a specified interval.&lt;/p&gt;

&lt;h4&gt;
  
  
  Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setInterval(function, interval);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example: Repeating a Function Every 2 Seconds
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setInterval(() =&amp;gt; {
    console.log("This message repeats every 2 seconds!");
}, 2000);

/* Output (every 2 seconds):
This message repeats every 2 seconds!
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Stopping setInterval() with clearInterval()
&lt;/h4&gt;

&lt;p&gt;To stop the interval, use clearInterval() with the interval ID returned by setInterval().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let count = 0;
let intervalId = setInterval(() =&amp;gt; {
    count++;
    console.log(`Count: ${count}`);

    if (count === 5) {
        clearInterval(intervalId); // Stops the interval after 5 repetitions
        console.log("Interval stopped!");
    }
}, 1000);

/* Output:
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
Interval stopped!
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;this&lt;/code&gt; with Arrow Functions in JavaScript
&lt;/h3&gt;

&lt;p&gt;Arrow functions (&lt;code&gt;=&amp;gt;&lt;/code&gt;) &lt;strong&gt;do not have their own &lt;code&gt;this&lt;/code&gt;&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Instead, they &lt;strong&gt;inherit &lt;code&gt;this&lt;/code&gt; from the surrounding (lexical) scope&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. &lt;code&gt;this&lt;/code&gt; in Regular Functions vs Arrow Functions
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = {
    name: "Alice",
    greet: function() {
        console.log(`Hello, my name is ${this.name}`);
    }
};

person.greet();  
// Output: "Hello, my name is Alice"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Issue with this in Regular Functions Inside setTimeout()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person2 = {
    name: "Bob",
    greet: function() {
        setTimeout(function() {
            console.log(`Hello, my name is ${this.name}`);
        }, 1000);
    }
};

person2.greet();
// Output: "Hello, my name is undefined"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function inside setTimeout() creates its own this, which refers to window (global object) instead of person2.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Fix Using Arrow Function (this is Inherited)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let personFixed = {
    name: "Bob",
    greet: function() {
        setTimeout(() =&amp;gt; {
            console.log(`Hello, my name is ${this.name}`);
        }, 1000);
    }
};

personFixed.greet();
// Output (after 1 second): "Hello, my name is Bob"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrow functions inherit this from the surrounding function (greet), so this.name correctly refers to "Bob".&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Arrow Functions Inside Object Methods
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person3 = {
    name: "Charlie",
    greet: () =&amp;gt; {
        console.log(`Hello, my name is ${this.name}`);
    }
};

person3.greet();
// Output: "Hello, my name is undefined"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since arrow functions do not have their own this, this refers to the global object (window in browsers, {} in Node.js).&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Arrow Functions in Event Listeners (this Issue)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.querySelector("button").addEventListener("click", () =&amp;gt; {
    console.log(this);  // `this` refers to `window`, not the button element
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;forEach()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;forEach()&lt;/code&gt; method&lt;/strong&gt; is used to &lt;strong&gt;iterate over elements in an array&lt;/strong&gt; and execute a function for each element.&lt;br&gt;&lt;br&gt;
It is a &lt;strong&gt;cleaner alternative&lt;/strong&gt; to &lt;code&gt;for&lt;/code&gt; loops.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.forEach(function(element, index, array) {
    // Code to execute
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;map()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;map()&lt;/code&gt; method&lt;/strong&gt; creates a &lt;strong&gt;new array&lt;/strong&gt; by applying a function to each element in an existing array.&lt;br&gt;&lt;br&gt;
It is commonly used for &lt;strong&gt;transforming&lt;/strong&gt; arrays.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.map(function(element, index, array) {
    return transformedElement;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;map()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;map()&lt;/code&gt; method&lt;/strong&gt; creates a &lt;strong&gt;new array&lt;/strong&gt; by applying a function to each element in an existing array.&lt;br&gt;&lt;br&gt;
It is commonly used for &lt;strong&gt;transforming&lt;/strong&gt; arrays.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.map(function(element, index, array) {
    return transformedElement;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;every()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;every()&lt;/code&gt; method&lt;/strong&gt; checks &lt;strong&gt;whether all elements&lt;/strong&gt; in an array &lt;strong&gt;pass a given condition&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It returns &lt;strong&gt;&lt;code&gt;true&lt;/code&gt; if all elements pass the test, otherwise &lt;code&gt;false&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.every(function(element, index, array) {
    return condition;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;some()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;some()&lt;/code&gt; method&lt;/strong&gt; checks if &lt;strong&gt;at least one element&lt;/strong&gt; in an array &lt;strong&gt;passes a given condition&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It returns &lt;strong&gt;&lt;code&gt;true&lt;/code&gt; if at least one element satisfies the condition, otherwise &lt;code&gt;false&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.some(function(element, index, array) {
    return condition;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;reduce()&lt;/code&gt; Method in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;reduce()&lt;/code&gt; method&lt;/strong&gt; in JavaScript reduces an array to &lt;strong&gt;a single value&lt;/strong&gt; by applying a function to each element.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.reduce(function(accumulator, element, index, array) {
    return updatedAccumulator;
}, initialValue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Finding the Maximum Value in an Array
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [4, 8, 2, 10, 5];

let maxNumber = numbers.reduce((max, num) =&amp;gt; num &amp;gt; max ? num : max, numbers[0]);

console.log(maxNumber);
// Output: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Default Parameters in JavaScript
&lt;/h3&gt;

&lt;p&gt;In JavaScript, &lt;strong&gt;default parameters&lt;/strong&gt; allow you to &lt;strong&gt;set a default value&lt;/strong&gt; for a function parameter.&lt;br&gt;&lt;br&gt;
If the argument is &lt;strong&gt;not provided&lt;/strong&gt;, the default value is used.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function functionName(param = defaultValue) {
    // Function body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Spread Operator (&lt;code&gt;...&lt;/code&gt;) in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;spread operator (&lt;code&gt;...&lt;/code&gt;)&lt;/strong&gt; in JavaScript is used to &lt;strong&gt;expand arrays, objects, or function arguments&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It provides a &lt;strong&gt;clean and concise&lt;/strong&gt; way to handle data.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newArray = [...existingArray];
const newObject = { ...existingObject };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Using Spread with Arrays
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let fruits = ["Apple", "Banana", "Cherry"];
let newFruits = [...fruits];

console.log(newFruits);
// Output: ["Apple", "Banana", "Cherry"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using Spread with Objects
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user = { name: "Alice", age: 25 };
let newUser = { ...user };

console.log(newUser);
// Output: { name: "Alice", age: 25 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Using Spread in Function Arguments
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sum(a, b, c) {
    return a + b + c;
}

let numbers = [1, 2, 3];

console.log(sum(...numbers));
// Output: 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Removing Elements from an Object
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user = { name: "Alice", age: 25, city: "New York" };

let { city, ...userWithoutCity } = user;

console.log(userWithoutCity);
// Output: { name: "Alice", age: 25 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rest Parameter (&lt;code&gt;...&lt;/code&gt;) in JavaScript
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;rest parameter (&lt;code&gt;...&lt;/code&gt;)&lt;/strong&gt; in JavaScript allows functions to accept an &lt;strong&gt;indefinite number of arguments&lt;/strong&gt; as an array.&lt;br&gt;&lt;br&gt;
It helps in handling &lt;strong&gt;multiple arguments dynamically&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Basic Syntax
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function functionName(...restParameter) {
    // Function body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Using Rest Parameters in Functions
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sum(...numbers) {
    return numbers.reduce((total, num) =&amp;gt; total + num, 0);
}

console.log(sum(1, 2, 3, 4, 5));
// Output: 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using Rest Parameters in Array Destructuring
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let [first, second, ...rest] = [10, 20, 30, 40, 50];

console.log(first);  // Output: 10
console.log(second); // Output: 20
console.log(rest);   // Output: [30, 40, 50]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Using Rest Parameters in Object Destructuring
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user = { name: "Alice", age: 25, city: "New York", job: "Developer" };

let { name, ...restInfo } = user;

console.log(name);      // Output: "Alice"
console.log(restInfo);  // Output: { age: 25, city: "New York", job: "Developer" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Destructuring in JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Destructuring&lt;/strong&gt; in JavaScript allows you to &lt;strong&gt;extract values from arrays and objects&lt;/strong&gt; into variables easily.&lt;br&gt;&lt;br&gt;
It makes code &lt;strong&gt;cleaner, shorter, and more readable&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Array Destructuring
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let colors = ["Red", "Green", "Blue"];

let [first, second, third] = colors;

console.log(first);  // Output: "Red"
console.log(second); // Output: "Green"
console.log(third);  // Output: "Blue"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Skipping Elements in Array Destructuring
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1, 2, 3, 4, 5];

let [first, , third] = numbers;

console.log(first);  // Output: 1
console.log(third);  // Output: 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Using Rest (...) in Array Destructuring
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let fruits = ["Apple", "Banana", "Cherry", "Mango"];

let [first, ...rest] = fruits;

console.log(first);  // Output: "Apple"
console.log(rest);   // Output: ["Banana", "Cherry", "Mango"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Object Destructuring
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let person = { name: "Alice", age: 25, city: "New York" };

let { name, age, city } = person;

console.log(name);  // Output: "Alice"
console.log(age);   // Output: 25
console.log(city);  // Output: "New York"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Changing Variable Names in Object Destructuring
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let user = { username: "Bob", age: 30 };

let { username: name, age: userAge } = user;

console.log(name);    // Output: "Bob"
console.log(userAge); // Output: 30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>coding</category>
    </item>
    <item>
      <title>Spotify Clone - HTML &amp; CSS Guide</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Sat, 08 Feb 2025 19:43:26 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/spotify-clone-html-css-guide-1e9</link>
      <guid>https://dev.to/_bhupeshk_/spotify-clone-html-css-guide-1e9</guid>
      <description>&lt;p&gt;A simple &lt;strong&gt;Spotify Clone&lt;/strong&gt; built using &lt;strong&gt;HTML and CSS&lt;/strong&gt; to replicate the look and feel of Spotify’s web player UI. This project is purely for frontend practice and &lt;strong&gt;does not include any backend functionality&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 &lt;strong&gt;Overview&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This project is a front-end implementation of Spotify's UI using &lt;strong&gt;only HTML and CSS&lt;/strong&gt;. It helps beginners understand how to structure a music streaming UI and style it using modern CSS techniques. The project focuses on &lt;strong&gt;layout, responsiveness, and design aesthetics&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✨ &lt;strong&gt;Key Features&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Homepage UI&lt;/strong&gt; - Looks similar to Spotify’s web player
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Navigation Bar&lt;/strong&gt; - Sidebar for easy navigation
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Music Player UI&lt;/strong&gt; - Includes a play/pause button, progress bar, and controls
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grid-Based Layout&lt;/strong&gt; - Uses CSS Grid and Flexbox for alignment
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hover Effects&lt;/strong&gt; - Smooth effects for an interactive feel
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive Design&lt;/strong&gt; - Works across different screen size &lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🛠 &lt;strong&gt;Technologies Used&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;HTML5 - Structuring the web page
&lt;/li&gt;
&lt;li&gt;CSS3 - Styling and layout (Flexbox, Grid, animations)
&lt;/li&gt;
&lt;li&gt;Google Fonts &amp;amp; Icons - Enhancing the UI
&lt;/li&gt;
&lt;li&gt;Media Queries - Making it responsive
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧐 &lt;strong&gt;Why is this project useful?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This project helps in:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Learning UI/UX development&lt;/strong&gt; - Understand how to structure and style a web application
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practicing CSS Layouts&lt;/strong&gt; - Uses &lt;strong&gt;Flexbox, Grid, and positioning&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improving Web Design Skills&lt;/strong&gt; - Focus on clean and modern design
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understanding Responsive Design&lt;/strong&gt; - Adapts to different screen sizes
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🚀 &lt;strong&gt;How to Run the Project?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repository:
&lt;code&gt;git clone https://github.com/bhupeshk3014/spotify-clone-css&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open &lt;code&gt;index.html&lt;/code&gt; in your browser.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enjoy the Spotify UI experience!&lt;/strong&gt; 🎧
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  📸 &lt;strong&gt;Screenshots&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj98ao52nkzzv316mv3nz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj98ao52nkzzv316mv3nz.png" alt="Spotify Clone Screenshot" width="800" height="421"&gt;&lt;/a&gt; &lt;/p&gt;




&lt;h3&gt;
  
  
  🔗 &lt;strong&gt;GitHub Repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/bhupeshk3014/spotify-clone-css" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Web Dev Day 5: Bootstrap Guide</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Mon, 03 Jun 2024 02:12:14 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/web-dev-day-5-bootstrap-guide-359p</link>
      <guid>https://dev.to/_bhupeshk_/web-dev-day-5-bootstrap-guide-359p</guid>
      <description>&lt;h2&gt;
  
  
  What is Bootstrap?
&lt;/h2&gt;

&lt;p&gt;Bootstrap is a popular open-source front-end framework used for developing responsive and mobile-first websites quickly and efficiently. It was originally developed by Twitter and released in 2011.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Responsive Grid System&lt;/strong&gt;: A flexible 12-column layout system for creating responsive designs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pre-styled Components&lt;/strong&gt;: Includes a wide range of UI components like buttons, forms, navbars, modals, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS and JavaScript&lt;/strong&gt;: Provides CSS styles and JavaScript plugins for enhanced functionality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customization&lt;/strong&gt;: Easily customizable using Sass variables and built-in themes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-browser Compatibility&lt;/strong&gt;: Ensures consistency across modern browsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extensive Documentation and Community Support&lt;/strong&gt;: Large community and comprehensive documentation available.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Basic Example
&lt;/h3&gt;

&lt;p&gt;A simple Bootstrap layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Bootstrap Example&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-md-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Column 1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-md-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Column 2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-md-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Column 3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap simplifies the process of designing responsive, visually appealing web pages with its ready-to-use components and customization options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Bootstrap
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Responsive Design&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mobile-first approach ensures websites look great on all devices.&lt;/li&gt;
&lt;li&gt;12-column grid system for flexible layouts.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Pre-styled Components&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistent design with buttons, forms, navbars, and more.&lt;/li&gt;
&lt;li&gt;Saves time on custom styling.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Customizable&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easily modify default styles with Sass variables.&lt;/li&gt;
&lt;li&gt;Supports custom themes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cross-browser Compatibility&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensures uniform appearance across all major browsers.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Comprehensive Documentation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Detailed documentation with examples and code snippets.&lt;/li&gt;
&lt;li&gt;Large community support.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Built-in JavaScript Plugins&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enhances functionality with interactive components like modals and carousels.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Standardized UI elements for a uniform look and feel.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Speed of Development&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rapid prototyping with ready-to-use components.&lt;/li&gt;
&lt;li&gt;Reusable components across projects.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Integration with Other Tools&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compatible with modern frameworks (React, Angular, Vue.js).&lt;/li&gt;
&lt;li&gt;Works with build tools like Webpack and Gulp.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Accessibility&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Supports ARIA attributes for better accessibility.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bootstrap helps developers build responsive, consistent, and visually appealing websites quickly and efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Bootstrap
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Include Bootstrap in Your Project&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Using a CDN:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quick and easy way to get started.&lt;/li&gt;
&lt;li&gt;Add Bootstrap CSS and JS files via a CDN link in your HTML.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Using NPM:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Bootstrap for projects using Node.js.&lt;/li&gt;
&lt;li&gt;Import Bootstrap CSS and JS in your project files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Create a Basic Layout&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Utilize Bootstrap's responsive grid system.&lt;/li&gt;
&lt;li&gt;Structure your layout using containers, rows, and columns to create a responsive design.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Use Bootstrap Components&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Buttons:&lt;/strong&gt; Pre-styled button classes for various styles (e.g., &lt;code&gt;btn-primary&lt;/code&gt;, &lt;code&gt;btn-secondary&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forms:&lt;/strong&gt; Form controls with built-in validation styles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Navbar:&lt;/strong&gt; Responsive navigation bar components.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Customize Bootstrap&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Using Sass:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modify Bootstrap's default styles with Sass variables.&lt;/li&gt;
&lt;li&gt;Create a custom Sass file to override Bootstrap variables and compile it into custom CSS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bootstrap simplifies web development with its responsive grid system, pre-styled components, and extensive customization options. It allows for rapid development of consistent and visually appealing websites while ensuring responsiveness and cross-browser compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Container
&lt;/h2&gt;

&lt;p&gt;In Bootstrap, a container is a layout element used to contain and organize content within a web page. There are two types: &lt;code&gt;.container&lt;/code&gt; for fixed-width content and &lt;code&gt;.container-fluid&lt;/code&gt; for full-width content.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.container&lt;/code&gt;&lt;/strong&gt;: Provides a fixed-width container for content. Ideal for standard layouts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.container-fluid&lt;/code&gt;&lt;/strong&gt;: Creates a full-width container that spans the entire viewport. Suitable for wide layouts or sections.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structuring Content&lt;/strong&gt;: Wraps content to ensure consistent spacing and alignment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive Design&lt;/strong&gt;: Adapts to different screen sizes for readability and aesthetics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grid System Alignment&lt;/strong&gt;: Works seamlessly with Bootstrap's grid system for responsive layouts.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Fixed-width content --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container-fluid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Full-width content --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap's container classes provide a framework for creating structured, responsive web layouts with ease.&lt;/p&gt;

&lt;h2&gt;
  
  
  Buttons
&lt;/h2&gt;

&lt;p&gt;Bootstrap buttons come in various styles and sizes, making it easy to add interactive elements to your website. Here’s a quick rundown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Styles&lt;/strong&gt;: Bootstrap provides styles for primary, secondary, success, warning, danger, info, light, and dark buttons. There are also outline buttons for a different look.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sizes&lt;/strong&gt;: Buttons can be large, medium, small, or block-level (full-width).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage&lt;/strong&gt;: Use primary buttons for main actions, secondary buttons for alternate actions, and other styles for specific contexts or emphasis.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Primary&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-secondary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Secondary&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-success"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Success&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-outline-danger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Danger&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap buttons provide consistency and responsiveness, making them a convenient choice for web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Badges
&lt;/h2&gt;

&lt;p&gt;Bootstrap badges are small components used to highlight information or provide visual feedback. Here's a quick summary with examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Badges offer visual indicators, flexible usage, and customization options.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Notifications &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"badge badge-light"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;5&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-success"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Inbox &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"badge badge-pill badge-danger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;10&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;h4&amp;gt;&lt;/span&gt;Important &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"badge badge-warning"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;!&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/h4&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap badges are versatile and can be added to buttons, links, or headings to display counts, statuses, or other relevant information in a visually appealing manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alert
&lt;/h2&gt;

&lt;p&gt;Bootstrap alerts provide contextual feedback messages to users. Here's a brief summary with examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Alerts offer contextual styles, dismissible options, and flexible usage.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert alert-success"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Success alert!
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert alert-warning"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Warning alert!
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert alert-danger"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Error alert!
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert alert-info"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Info alert!
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap alerts are versatile and can be easily integrated into any part of a webpage to provide feedback or notifications to users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Button Group
&lt;/h2&gt;

&lt;p&gt;Bootstrap button groups allow you to group buttons together for better organization and appearance. Here's a quick summary with an example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Button groups organize multiple buttons, ensuring visual consistency and responsive behavior.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn-group"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"group"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Basic example"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Left&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Middle&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Right&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap button groups help improve user interfaces by grouping related buttons together in a visually consistent manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Navbar
&lt;/h2&gt;

&lt;p&gt;Bootstrap navbar is a responsive navigation component that's easy to customize. Here's a quick overview with an example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Navbar adjusts for different screen sizes, supports various styles, and accommodates flexible content.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar navbar-expand-lg navbar-light bg-light"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar-brand"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Navbar&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar-toggler"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;data-toggle=&lt;/span&gt;&lt;span class="s"&gt;"collapse"&lt;/span&gt; &lt;span class="na"&gt;data-target=&lt;/span&gt;&lt;span class="s"&gt;"#navbarNav"&lt;/span&gt; &lt;span class="na"&gt;aria-controls=&lt;/span&gt;&lt;span class="s"&gt;"navbarNav"&lt;/span&gt; &lt;span class="na"&gt;aria-expanded=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Toggle navigation"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar-toggler-icon"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"collapse navbar-collapse"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"navbarNav"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar-nav"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-item active"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-link"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sr-only"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;(current)&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-link"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Features&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-link"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Pricing&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap navbar simplifies navigation setup with its responsive design and easy-to-use components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Card
&lt;/h2&gt;

&lt;p&gt;Bootstrap cards are versatile containers for displaying content. Here's a concise summary with an example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Cards offer flexibility, responsiveness, and customization options.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"width: 18rem;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card-img-top"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card-body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h5&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Card title&lt;span class="nt"&gt;&amp;lt;/h5&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Some quick example text to build on the card title and make up the bulk of the card's content.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Go somewhere&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap cards simplify content presentation with their adaptable design and numerous customization possibilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Grid
&lt;/h2&gt;

&lt;p&gt;Bootstrap's grid system is a flexible way to create responsive layouts. Here's a quick summary with an example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Responsive, based on a 12-column layout, and easy to use.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-sm-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Column 1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-sm-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Column 2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-sm-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Column 3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap's grid system simplifies layout creation, providing flexibility and responsiveness across devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Form Controls
&lt;/h2&gt;

&lt;p&gt;Bootstrap's form controls offer pre-styled elements for easy form creation. Here's a quick summary with examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Pre-styled form inputs, selects, textareas, and more for consistent appearance and validation states.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"exampleInputUsername"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Username&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"exampleInputUsername"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter username"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"exampleInputEmail"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"exampleInputEmail"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-group"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"exampleTextarea"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Example textarea&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;textarea&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"exampleTextarea"&lt;/span&gt; &lt;span class="na"&gt;rows=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap's form controls simplify form creation and enhance user experience with consistent styling and validation states.&lt;/p&gt;

&lt;h2&gt;
  
  
  Select in Forms
&lt;/h2&gt;

&lt;p&gt;Bootstrap's select dropdowns offer pre-styled options for form selections. Here's a brief summary with an example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: Styled select dropdowns for consistent appearance and responsiveness.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;select&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-select"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Default select example"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;selected&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Open this select menu&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Option 1&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Option 2&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Option 3&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap select dropdowns enhance form elements with consistent styling and usability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checkbox and Radio in Form
&lt;/h2&gt;

&lt;p&gt;Bootstrap's pre-styled checkboxes and radio buttons enhance form inputs with consistent styling and functionality. Here's a brief summary with examples:&lt;/p&gt;

&lt;h3&gt;
  
  
  Checkbox Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-check"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-check-input"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"defaultCheck1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-check-label"&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"defaultCheck1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Default checkbox
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Radio Button Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-check"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-check-input"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"exampleRadios"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"exampleRadios1"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"option1"&lt;/span&gt; &lt;span class="na"&gt;checked&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-check-label"&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"exampleRadios1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Default radio
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap's styled checkboxes and radio buttons improve the appearance and usability of form inputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Form Layout
&lt;/h2&gt;

&lt;p&gt;Bootstrap's form layout system enables the creation of structured and responsive forms with ease. Here's a concise overview with an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"row mb-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-md-6"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"inputEmail"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-label"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"inputEmail"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"col-md-6"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"inputPassword"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-label"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Password&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"inputPassword"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"mb-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"exampleTextarea"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-label"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Textarea&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;textarea&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-control"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"exampleTextarea"&lt;/span&gt; &lt;span class="na"&gt;rows=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap's form layout system simplifies the creation of responsive and structured forms, ensuring consistency and usability across different screen sizes.&lt;/p&gt;

&lt;p&gt;Bootstrap Website: &lt;a href="https://getbootstrap.com/docs/5.3/getting-started/introduction/"&gt;https://getbootstrap.com/docs/5.3/getting-started/introduction/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>bootstrap</category>
      <category>programming</category>
      <category>css</category>
    </item>
    <item>
      <title>242. Valid Anagram</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Thu, 16 May 2024 19:58:33 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/242-valid-anagram-4abc</link>
      <guid>https://dev.to/_bhupeshk_/242-valid-anagram-4abc</guid>
      <description>&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given two strings s and t, return true if t is an anagram of s, and false otherwise.&lt;/p&gt;

&lt;p&gt;An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example 1:

Input: s = "anagram", t = "nagaram"
Output: true

Example 2:

Input: s = "rat", t = "car"
Output: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;1 &amp;lt;= s.length, t.length &amp;lt;= 5 * 104&lt;/code&gt;&lt;br&gt;
&lt;code&gt;s and t consist of lowercase English letters&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Approach 1: Using Hashmap
&lt;/h2&gt;

&lt;p&gt;This code utilizes a HashMap to track the occurrences of characters in one string and adjusts these counts based on the characters in the second string. By ensuring that all character counts become zero, it confirms if the strings are basic anagrams of each other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public boolean isAnagram(String s, String t) {

        Map&amp;lt;Character, Integer&amp;gt; mp = new HashMap&amp;lt;&amp;gt;();
        for (int i = 0; i &amp;lt; s.length(); i++) {
            char ch = s.charAt(i);
            mp.put(ch, mp.getOrDefault(ch, 0) + 1);
        }

        for (int i = 0; i &amp;lt; t.length(); i++) {
            char ch = t.charAt(i);
            if (!mp.containsKey(ch) || mp.get(ch) == 0) {
                return false;
            }
            mp.put(ch, mp.get(ch) - 1);
        }     

        for (int count : mp.values()) {
            if (count != 0) {
                return false;
            }
        }

        return true;

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

&lt;/div&gt;



&lt;p&gt;Runtime: 16ms&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach 2: Using Arrays&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Arrays;

class Solution {
    public boolean isAnagram(String s, String t) {
        // Check if lengths are equal, if not, they can't be anagrams
        if (s.length() != t.length())
            return false;

        // Convert strings to character arrays
        char[] sChars = s.toCharArray();
        char[] tChars = t.toCharArray();

        // Sort character arrays
        Arrays.sort(sChars);
        Arrays.sort(tChars);

        // Compare sorted character arrays
        return Arrays.equals(sChars, tChars);
    }
}

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

&lt;/div&gt;



&lt;p&gt;Runtime: 4ms&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach 3: Hash Table (Using Array)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public boolean isAnagram(String s, String t) {
        // Create an array to store the count of occurrences of each character (26 lowercase letters)
        int[] count = new int[26];

        // Iterate through the characters of string s
        for (char x : s.toCharArray()) {
            // Increment the count for the character 'x' (subtracting 'a' gives the index corresponding to 'x')
            count[x - 'a']++;
        }

        // Iterate through the characters of string t
        for (char x : t.toCharArray()) {
            // Decrement the count for the character 'x' (subtracting 'a' gives the index corresponding to 'x')
            count[x - 'a']--;
        }

        // Check if all counts in the array are zero
        for (int val : count) {
            if (val != 0) {
                // If any count is not zero, return false indicating strings are not anagrams
                return false;
            }
        }

        // If all counts are zero, return true indicating strings are anagrams
        return true;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Runtime: 2ms&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>dsa</category>
      <category>coding</category>
      <category>programming</category>
    </item>
    <item>
      <title>Web Dev Day 4: CSS3 Guide Part 2</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Thu, 16 May 2024 18:54:24 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/web-dev-day-4-css3-guide-part-2-jk9</link>
      <guid>https://dev.to/_bhupeshk_/web-dev-day-4-css3-guide-part-2-jk9</guid>
      <description>&lt;h2&gt;
  
  
  Alpha Channel:
&lt;/h2&gt;

&lt;p&gt;The alpha channel, often referred to as opacity or transparency, is a component of the RGB color model that represents the degree of transparency of a color. It determines how much of an underlying color or background is visible through a particular color.&lt;/p&gt;

&lt;p&gt;In CSS, the alpha channel is typically represented using the rgba() color function or the hsla() color function:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. rgba() Function:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stands for "red, green, blue, alpha."&lt;br&gt;
The alpha value is specified as a number between 0 (fully transparent) and 1 (fully opaque).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* RGBA color with 50% opacity */
background-color: rgba(255, 0, 0, 0.5); /* Red color with 50% opacity */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. hsla() Function:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stands for "hue, saturation, lightness, alpha."&lt;br&gt;
The alpha value is specified as a number between 0 (fully transparent) and 1 (fully opaque).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* HSLA color with 50% opacity */
background-color: hsla(0, 100%, 50%, 0.5); /* Red color with 50% opacity */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Opacity:
&lt;/h2&gt;

&lt;p&gt;In CSS, the opacity property is used to set the transparency level of an element. It affects the entire element, including its content and any child elements. The opacity property takes a value between 0 (completely transparent) and 1 (completely opaque).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Make the element 70% transparent */
div {
    opacity: 0.7;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS Transition:
&lt;/h2&gt;

&lt;p&gt;CSS transitions provide a way to smoothly animate the changing of property values over time. Transitions are often used to create subtle and visually appealing effects when interacting with web elements. Here's an overview of CSS transitions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;selector {
    property: value;
    transition: property duration timing-function delay;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Apply a transition to the background-color property */
button {
    background-color: blue;
    transition: background-color 0.5s ease-in-out;
}

/* Change the background color on hover */
button:hover {
    background-color: red;
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Transition Shorthand:
&lt;/h2&gt;

&lt;p&gt;The transition property can also be written using the shorthand syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;selector {
    transition: property duration timing-function delay;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common Transition Properties:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;all: Transitions all properties.&lt;/li&gt;
&lt;li&gt;transform: Transitions for 2D and 3D transformations.&lt;/li&gt;
&lt;li&gt;opacity: Transitions for opacity changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;transform&lt;/code&gt;:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Apply a transition to the transform property */
div {
    transform: scale(1);
    transition: transform 0.3s ease-in-out;
}

/* Scale the element on hover */
div:hover {
    transform: scale(1.2);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS Transform:
&lt;/h2&gt;

&lt;p&gt;CSS transform is a CSS property that allows you to apply various visual transformations to elements on a webpage. These transformations include translation, rotation, scaling, and skewing, enabling you to manipulate the appearance and layout of elements in two-dimensional or three-dimensional space.&lt;/p&gt;

&lt;p&gt;With CSS transform, you can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Translate&lt;/strong&gt;: Move an element along the X and Y axes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rotate&lt;/strong&gt;: Rotate an element clockwise or counterclockwise around a fixed point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scale&lt;/strong&gt;: Resize an element along the X and Y axes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skew&lt;/strong&gt;: Distort an element along the X and Y axes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3D Transformations&lt;/strong&gt;: Apply transformations in three-dimensional space, such as rotating around the X, Y, or Z axis.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These transformations can be applied individually or combined together to create complex visual effects and animations. CSS transform is widely used in web development to create responsive designs, animations, and interactive user interfaces.&lt;/p&gt;

&lt;p&gt;Here's an example of how CSS transform can be applied:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.element {
  transform: translate(50px, 50px) rotate(45deg) scale(1.5) skew(10deg, 20deg);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This CSS rule translates the element by 50 pixels on both the X and Y axes, rotates it by 45 degrees, scales it to 1.5 times its original size, and skews it by 10 degrees along the X axis and 20 degrees along the Y axis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Box Shadow:
&lt;/h2&gt;

&lt;p&gt;CSS &lt;code&gt;box-shadow&lt;/code&gt; is a property used to add shadow effects to elements. It takes parameters for horizontal and vertical offsets, blur radius, spread radius, color, and inset (optional). &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box {
  box-shadow: 2px 2px 4px #888;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet adds a shadow with a horizontal offset of 2 pixels, vertical offset of 2 pixels, blur radius of 4 pixels, and a gray color.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background Image:
&lt;/h2&gt;

&lt;p&gt;CSS &lt;code&gt;background-image&lt;/code&gt; is a property used to set one or more background images for an element. It takes a URL pointing to the image file to be used as the background.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;background&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code snippet sets the image specified by &lt;code&gt;'image-url'&lt;/code&gt; as the background for the &lt;code&gt;.element&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Card Hover Effect:
&lt;/h2&gt;

&lt;p&gt;A card hover effect is a visual enhancement applied to a card element when a user hovers over it. This effect typically involves changes in properties like background color, shadow, scale, or position, creating an interactive and engaging experience.&lt;/p&gt;

&lt;p&gt;Here's a concise example using CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.card {
  /* Card styles */
  transition: transform 0.3s ease;
}

.card:hover {
  transform: translateY(-5px);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, when the user hovers over the &lt;code&gt;.card&lt;/code&gt;, it moves upward by 5 pixels due to the &lt;code&gt;transform: translateY(-5px)&lt;/code&gt; property. The &lt;code&gt;transition&lt;/code&gt; property ensures a smooth animation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Position Property:
&lt;/h2&gt;

&lt;p&gt;The CSS &lt;code&gt;position&lt;/code&gt; property determines how an element is positioned on a webpage. It can take values like &lt;code&gt;static&lt;/code&gt;, &lt;code&gt;relative&lt;/code&gt;, &lt;code&gt;absolute&lt;/code&gt;, &lt;code&gt;fixed&lt;/code&gt;, or &lt;code&gt;sticky&lt;/code&gt;, each affecting the element's positioning behavior in different ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flexbox:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Flexbox&lt;/strong&gt; is a layout model in CSS that allows you to create flexible and responsive layouts with ease.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Display Flex&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;display: flex;&lt;/code&gt; turns a container's children into flex items, enabling the use of flexbox properties.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Flex Direction&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;flex-direction&lt;/code&gt; determines the main axis of the flex container and the direction in which flex items are laid out. Values include &lt;code&gt;row&lt;/code&gt;, &lt;code&gt;row-reverse&lt;/code&gt;, &lt;code&gt;column&lt;/code&gt;, and &lt;code&gt;column-reverse&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Justify Content&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;justify-content&lt;/code&gt; aligns flex items along the main axis of the flex container. Common values are &lt;code&gt;flex-start&lt;/code&gt;, &lt;code&gt;flex-end&lt;/code&gt;, &lt;code&gt;center&lt;/code&gt;, &lt;code&gt;space-between&lt;/code&gt;, and &lt;code&gt;space-around&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Flex Wrap&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;flex-wrap&lt;/code&gt; controls whether flex items are forced onto a single line or can wrap onto multiple lines. Values include &lt;code&gt;nowrap&lt;/code&gt;, &lt;code&gt;wrap&lt;/code&gt;, and &lt;code&gt;wrap-reverse&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Align Items&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;align-items&lt;/code&gt; aligns flex items along the cross axis of the flex container. Common values are &lt;code&gt;flex-start&lt;/code&gt;, &lt;code&gt;flex-end&lt;/code&gt;, &lt;code&gt;center&lt;/code&gt;, &lt;code&gt;baseline&lt;/code&gt;, and &lt;code&gt;stretch&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Align Content&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;align-content&lt;/code&gt; aligns flex lines (when there is more than one) along the cross axis. Values include &lt;code&gt;flex-start&lt;/code&gt;, &lt;code&gt;flex-end&lt;/code&gt;, &lt;code&gt;center&lt;/code&gt;, &lt;code&gt;space-between&lt;/code&gt;, &lt;code&gt;space-around&lt;/code&gt;, and &lt;code&gt;stretch&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Align Self&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;align-self&lt;/code&gt; allows individual flex items to override the &lt;code&gt;align-items&lt;/code&gt; property for alignment along the cross axis.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Flex Sizing&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flex items can be given a flex basis, flex-grow factor, and flex-shrink factor to control their size within the flex container.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Flex Shorthand&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;flex&lt;/code&gt; shorthand property combines &lt;code&gt;flex-grow&lt;/code&gt;, &lt;code&gt;flex-shrink&lt;/code&gt;, and &lt;code&gt;flex-basis&lt;/code&gt; properties in a single declaration.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Flexbox simplifies the process of creating complex layouts, making it easier to create responsive designs and align content in a more dynamic and flexible way.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Grid?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Grid&lt;/strong&gt; is a layout model in CSS that enables you to create complex grid-based layouts with rows and columns.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Grid Model&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grid layout divides a container into rows and columns, creating a grid structure for arranging elements.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Grid Template&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;grid-template&lt;/code&gt; property defines the layout of the grid using a combination of track sizing functions and line names.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Repeat&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;repeat()&lt;/code&gt; function specifies a repeating pattern for track sizing. For example, &lt;code&gt;repeat(3, 1fr)&lt;/code&gt; repeats the track size &lt;code&gt;1fr&lt;/code&gt; three times.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Grid Gaps&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;grid-gap&lt;/code&gt; property sets the size of the gap between grid rows and columns. It is a shorthand for &lt;code&gt;grid-row-gap&lt;/code&gt; and &lt;code&gt;grid-column-gap&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Grid Columns&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;grid-template-columns&lt;/code&gt; property defines the size of grid columns. You can specify the size of each column individually or use track sizing functions like &lt;code&gt;auto&lt;/code&gt;, &lt;code&gt;1fr&lt;/code&gt;, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Grid Rows&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;grid-template-rows&lt;/code&gt; property defines the size of grid rows. Similar to &lt;code&gt;grid-template-columns&lt;/code&gt;, you can specify the size of each row individually or use track sizing functions.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Grid Properties&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Other grid properties include &lt;code&gt;grid-template-areas&lt;/code&gt; for defining named grid areas, &lt;code&gt;grid-column&lt;/code&gt; and &lt;code&gt;grid-row&lt;/code&gt; for positioning grid items within the grid, and various alignment properties like &lt;code&gt;justify-items&lt;/code&gt;, &lt;code&gt;align-items&lt;/code&gt;, &lt;code&gt;justify-content&lt;/code&gt;, and &lt;code&gt;align-content&lt;/code&gt; for aligning grid items within the grid container.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 100px auto;
  grid-gap: 10px;
}

.item {
  grid-column: 2 / span 1;
  grid-row: 1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;.container&lt;/code&gt; is a grid container with three columns of equal width and two rows (100 pixels in height for the first row and auto for the second row).&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;.item&lt;/code&gt; is a grid item positioned starting from the second column and spanning 1 column, and placed in the first row of the grid.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CSS Animation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;CSS Animation&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;CSS animations allow you to animate the properties of an element over a specified duration using keyframes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;animation-name&lt;/strong&gt;: Specifies the name of the @keyframes rule defining the animation's keyframes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;animation-duration&lt;/strong&gt;: Sets the duration of the animation in seconds or milliseconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;animation-timing-function&lt;/strong&gt;: Defines the timing function for the animation, specifying the pace of the animation's progression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;animation-delay&lt;/strong&gt;: Specifies the delay before the animation starts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;animation-iteration-count&lt;/strong&gt;: Sets the number of times the animation should repeat.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;animation-direction&lt;/strong&gt;: Defines whether the animation should play forwards, backwards, alternate between forward and backward, or alternate in reverse.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Define keyframes */
@keyframes slide {
  0% { transform: translateX(0); }
  100% { transform: translateX(200px); }
}

/* Apply animation */
.element {
  animation-name: slide;
  animation-duration: 2s;
  animation-timing-function: ease-in-out;
  animation-delay: 1s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Animation Shorthand
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.element {
  animation: slide 2s ease-in-out 1s infinite alternate;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.element&lt;/code&gt; is the selector for the element to be animated.&lt;/li&gt;
&lt;li&gt;The animation name is &lt;code&gt;slide&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Duration is 2 seconds.&lt;/li&gt;
&lt;li&gt;Timing function is &lt;code&gt;ease-in-out&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Delay is 1 second.&lt;/li&gt;
&lt;li&gt;Iteration count is infinite.&lt;/li&gt;
&lt;li&gt;Direction is alternate.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  % in Animation
&lt;/h2&gt;

&lt;p&gt;In CSS animations, percentages within &lt;code&gt;@keyframes&lt;/code&gt; define different stages of the animation's duration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes example-animation {
  0% {
    /* Styles at the beginning of the animation */
  }
  50% {
    /* Styles halfway through the animation */
  }
  100% {
    /* Styles at the end of the animation */
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;0%&lt;/code&gt; represents the start of the animation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;50%&lt;/code&gt; represents the middle of the animation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;100%&lt;/code&gt; represents the end of the animation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can specify styles at various percentages to create different effects throughout the animation's duration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Media Queries
&lt;/h2&gt;

&lt;p&gt;Media queries in CSS allow you to apply different styles based on various device characteristics, such as screen size, orientation, and device type.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Orientation&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;Media queries can target the orientation of the device, allowing you to apply different styles based on whether the device is in portrait or landscape mode.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media (orientation: portrait) {
  /* Styles for portrait orientation */
}

@media (orientation: landscape) {
  /* Styles for landscape orientation */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Media Features:&lt;/strong&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS/@media&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  z index
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;z-index&lt;/code&gt; property in CSS controls the stacking order of positioned elements. It determines which elements appear on top of others when they overlap on the z-axis.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Design Priciples
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Color Theory
&lt;/h2&gt;

&lt;p&gt;Color theory explores the principles and guidelines behind the use of color in art and design. Here's a brief overview:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Color Wheel&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The color wheel is a visual representation of colors arranged in a circular format. It consists of primary colors (red, blue, yellow), secondary colors (orange, green, purple), and tertiary colors (mixtures of primary and secondary colors).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Color Harmony&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Color harmony refers to the pleasing combination of colors in a design. Common color harmonies include:

&lt;ul&gt;
&lt;li&gt;Complementary: Colors opposite each other on the color wheel.&lt;/li&gt;
&lt;li&gt;Analogous: Colors adjacent to each other on the color wheel.&lt;/li&gt;
&lt;li&gt;Triadic: Three colors equally spaced on the color wheel.&lt;/li&gt;
&lt;li&gt;Monochromatic: Variations of a single color.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Color Properties&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hue: The actual color of an object (e.g., red, blue, green).&lt;/li&gt;
&lt;li&gt;Saturation: The intensity or purity of a color. More saturated colors are vivid, while less saturated colors are dull.&lt;/li&gt;
&lt;li&gt;Value: The lightness or darkness of a color. Tints are lighter values, while shades are darker values.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Color Psychology&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Colors can evoke different emotions and associations. For example, red may symbolize passion or danger, while blue may represent calmness or trust.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Color in Design&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In design, color is used to convey meaning, create visual interest, establish hierarchy, and evoke emotions. Understanding color theory helps designers make informed color choices to achieve their design goals.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Canva Color Wheel:&lt;/strong&gt; &lt;a href="https://www.canva.com/colors/color-wheel/"&gt;https://www.canva.com/colors/color-wheel/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Typography
&lt;/h2&gt;

&lt;p&gt;Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed. It involves selecting fonts, adjusting font size, line spacing, and letter spacing to create a harmonious and visually pleasing design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Google Fonts
&lt;/h2&gt;

&lt;p&gt;Google Fonts is a collection of free, open-source fonts provided by Google. It offers a wide variety of high-quality fonts that can be easily integrated into web projects. Web designers and developers can access Google Fonts via a simple link or import statement in their HTML or CSS files, making it convenient to use custom fonts in their designs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fonts.google.com/"&gt;https://fonts.google.com/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Icons
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://fonts.google.com/icons"&gt;https://fonts.google.com/icons&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fontawesome.com/icons"&gt;https://fontawesome.com/icons&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cdnjs.com/libraries/font-awesome"&gt;https://cdnjs.com/libraries/font-awesome&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css&lt;/a&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  CSS Mini Project
&lt;/h2&gt;

&lt;p&gt;This repository contains a simple HTML and CSS project showcasing a sidebar menu design. The project is designed to be lightweight and demonstrate fundamental techniques in creating responsive web layouts using HTML and CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Responsive sidebar menu&lt;/li&gt;
&lt;li&gt;Utilization of Font Awesome icons&lt;/li&gt;
&lt;li&gt;Basic hover effects&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Technologies Used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;Font Awesome&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Github Link: &lt;a href="https://github.com/bhupeshk3014/css-mini"&gt;https://github.com/bhupeshk3014/css-mini&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MDN Docs:&lt;/strong&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Arrays and ArrayList in JAVA</title>
      <dc:creator>Bhupesh Kumar</dc:creator>
      <pubDate>Thu, 09 May 2024 22:48:46 +0000</pubDate>
      <link>https://dev.to/_bhupeshk_/arrays-and-arraylist-in-java-1jc2</link>
      <guid>https://dev.to/_bhupeshk_/arrays-and-arraylist-in-java-1jc2</guid>
      <description>&lt;h2&gt;
  
  
  What is Array?
&lt;/h2&gt;

&lt;p&gt;An array in Java is a fixed-size collection of elements of the same data type. It allows you to store and access multiple values under a single variable name. Arrays are indexed starting from 0 and are useful for managing collections of data efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need Arrays?
&lt;/h2&gt;

&lt;p&gt;Arrays are essential because they:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Group related data under one variable.&lt;/li&gt;
&lt;li&gt;Allow efficient access to individual elements.&lt;/li&gt;
&lt;li&gt;Optimize memory usage.&lt;/li&gt;
&lt;li&gt;Facilitate iteration through elements.&lt;/li&gt;
&lt;li&gt;Enable passing data to functions efficiently.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Syntax of Array
&lt;/h2&gt;

&lt;p&gt;In Java, the syntax for declaring and initializing an array is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: declaring and initializing an array of integers with a size of 5
int[] numbers = new int[5];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can declare and initialize the array in separate steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers; // Declaration
numbers = new int[5]; // Initialization
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also initialize the array with values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: initializing an array of integers with specific values
int[] numbers = {10, 20, 30, 40, 50};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How does Array work?
&lt;/h2&gt;

&lt;p&gt;Arrays in Java store elements of the same data type in consecutive memory locations, accessible by index starting from 0. They have a fixed size and are efficient for accessing and manipulating data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Internal working of an Array
&lt;/h2&gt;

&lt;p&gt;Internally, arrays in Java are implemented as contiguous blocks of memory where elements of the same data type are stored sequentially. Here's a deeper look at how arrays work internally in Java:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memory Allocation&lt;/strong&gt;: When you declare an array in Java, memory is allocated for it based on the specified size and data type. This memory allocation is done from the heap, the region of memory reserved for dynamic memory allocation in Java.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Contiguous Storage&lt;/strong&gt;: Array elements are stored consecutively in memory, one after another. This contiguous storage ensures efficient memory access, as elements can be accessed directly using their indices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Indexing&lt;/strong&gt;: Each element in the array is assigned an index starting from 0. When you access an element of the array using its index, the Java runtime calculates the memory address of the element based on its index and the size of the data type.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Element Access&lt;/strong&gt;: Once the memory address of the desired element is calculated, the runtime retrieves the value stored at that address and returns it to the program. This process of accessing elements by index is very efficient, typically taking constant time, O(1).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fixed Size&lt;/strong&gt;: Arrays in Java have a fixed size, meaning their size cannot be changed after they are created. If you need to store more elements than the size of the array allows, you would need to create a new array with a larger size and copy the elements from the old array to the new one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Primitive vs. Reference Types&lt;/strong&gt;: Arrays can hold elements of primitive data types (such as int, float, char) or reference types (such as objects). When an array holds elements of reference types, it actually holds references (memory addresses) to the objects rather than the objects themselves.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Garbage Collection&lt;/strong&gt;: Arrays, like other objects in Java, are subject to automatic garbage collection. Once an array is no longer referenced by any part of the program, it becomes eligible for garbage collection, and the memory it occupies is reclaimed by the JVM.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Overall, arrays provide a low-level mechanism for efficiently storing and accessing collections of elements in memory, making them a fundamental data structure in Java.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuity of an Array
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Array objects are typically located in the heap&lt;/strong&gt;. In Java, arrays are objects, and as such, they are allocated memory on the heap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Heap objects are not necessarily stored contiguously&lt;/strong&gt;. While the elements within an array object are contiguous, the overall structure of the heap doesn't guarantee that objects are stored consecutively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Memory Allocation&lt;/strong&gt; is indeed used for arrays and other objects in Java. Memory for arrays is allocated at runtime, allowing for flexibility in memory usage.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Therefore, while the elements within an array are guaranteed to be stored contiguously, the arrangement of objects in the heap may not be continuous. This behavior is dependent on how the JVM manages memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Index of an Array
&lt;/h2&gt;

&lt;p&gt;The index of an array is a numeric value representing the position of an element within the array. It starts from 0, increments by 1 for each subsequent element, and allows for direct access to array elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  New Keyword
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;new&lt;/code&gt; keyword in Java is used to dynamically allocate memory for objects at runtime. It creates instances of classes, allocates memory on the heap, invokes constructors to initialize objects, returns references to the allocated memory, and enables automatic garbage collection.&lt;/p&gt;

&lt;h2&gt;
  
  
  String Array
&lt;/h2&gt;

&lt;p&gt;A string array in Java is an array that holds elements of type String. It allows you to store multiple strings under a single variable name, making it useful for managing collections of text data.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is null in JAVA?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;null&lt;/code&gt; in Java represents the absence of a value or an uninitialized object reference. It's used to indicate that a variable does not currently refer to any object and can lead to a &lt;code&gt;NullPointerException&lt;/code&gt; if accessed improperly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array Input
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;For loop&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        Scanner scanner = new Scanner(System.in);

        // Get the size of the array from the user
        System.out.print("Enter the size of the array: ");
        int size = scanner.nextInt();

        // Create the array
        int[] numbers = new int[size];

        // Input the elements of the array
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i &amp;lt; size; i++) {
            numbers[i] = scanner.nextInt();
        }

        // Display the elements of the array
        System.out.println("The elements of the array are:");
        for (int i = 0; i &amp;lt; size; i++) {
            System.out.println(numbers[i]);
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For each loop&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        Scanner scanner = new Scanner(System.in);

        // Get the size of the array from the user
        System.out.print("Enter the size of the array: ");
        int size = scanner.nextInt();

        // Create the array
        int[] numbers = new int[size];

        // Input the elements of the array
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i &amp;lt; size; i++) {
            numbers[i] = scanner.nextInt();
        }

        // Display the elements of the array using for-each loop
        System.out.println("The elements of the array are:");
        for (int number : numbers) {
            System.out.println(number);
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  toString() Method
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        int[] numbers = {1, 2, 3, 4, 5};
        String str = Arrays.toString(numbers);
        System.out.println(str); // Output: [1, 2, 3, 4, 5]

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Storage of objects in heap
&lt;/h2&gt;

&lt;p&gt;Objects in Java are stored in the heap memory. When you create an object using the &lt;code&gt;new&lt;/code&gt; keyword, memory is allocated on the heap to store its data, and a reference to this memory location is returned. Java's automatic garbage collection manages memory deallocation, ensuring efficient use of heap memory resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array passing in function
&lt;/h2&gt;

&lt;p&gt;You can pass arrays as parameters to functions in Java, allowing you to work with array elements within the function. Modifications made to the array within the function affect the original array. This enables modularization and reusability of code when working with arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ArrayExample {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 3, 4, 5};
        printArray(numbers); // Pass the array to the function
    }

    // Function to print array elements
    public static void printArray(int[] arr) {
        for (int i = 0; i &amp;lt; arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Multi-dimensional Arrays
&lt;/h2&gt;

&lt;p&gt;Multi-dimensional arrays in Java are arrays of arrays, allowing you to create tables or matrices with rows and columns. They are useful for representing data in multiple dimensions, such as 2D grids or 3D spaces.&lt;/p&gt;

&lt;p&gt;Here's an example of how to create and work with multi-dimensional arrays in Java:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MultiDimensionalArrayExample {
    public static void main(String[] args) {
        // Creating a 2D array (matrix)
        int[][] matrix = {
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9}
        };

        // Accessing elements of the 2D array
        System.out.println(matrix[0][0]); // Output: 1
        System.out.println(matrix[1][2]); // Output: 6

        // Iterating over the 2D array
        for (int i = 0; i &amp;lt; matrix.length; i++) {
            for (int j = 0; j &amp;lt; matrix[i].length; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Internal working of 2D Array
&lt;/h2&gt;

&lt;p&gt;can be written like&lt;/p&gt;

&lt;p&gt;&lt;code&gt;int[][] arr = new int[3][];&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;individual arrays can have different size&lt;/p&gt;

&lt;p&gt;A 2D array in Java is internally represented as an array of arrays, with elements stored row by row in contiguous memory locations. Accessing elements is efficient, using row and column indices to calculate the memory location directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  2D Array Input and Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

public class TwoDArrayInputOutput {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Get the dimensions of the 2D array from the user
        System.out.print("Enter the number of rows: ");
        int rows = scanner.nextInt();
        System.out.print("Enter the number of columns: ");
        int columns = scanner.nextInt();

        // Create the 2D array
        int[][] matrix = new int[rows][columns];

        // Input the elements of the 2D array
        System.out.println("Enter the elements of the 2D array:");
        for (int i = 0; i &amp;lt; rows; i++) {
            for (int j = 0; j &amp;lt; columns; j++) {
                matrix[i][j] = scanner.nextInt();
            }
        }

        // Output the 2D array
        System.out.println("The 2D array is:");
        for (int i = 0; i &amp;lt; rows; i++) {
            for (int j = 0; j &amp;lt; columns; j++) {
                System.out.print(matrix[i][j] + " ");
            }
            System.out.println();
        }

        scanner.close();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrays are Mutable&lt;/p&gt;

&lt;h2&gt;
  
  
  Complexity Analysis of Operations on Array:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Operation:&lt;/p&gt;

&lt;p&gt;Traversal O(N)&lt;br&gt;
Insertion O(N)&lt;br&gt;
Deletion O(N)&lt;br&gt;
Searching O(N)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space Complexity:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Operation:&lt;/p&gt;

&lt;p&gt;Traversal O(1)&lt;br&gt;
Insertion O(N)&lt;br&gt;
Deletion O(N)&lt;br&gt;
Searching O(1)&lt;/p&gt;
&lt;h2&gt;
  
  
  Advantages of Array:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Arrays allow random access to elements. This makes accessing elements by position faster.&lt;/li&gt;
&lt;li&gt;Arrays have better cache locality which makes a pretty big difference in performance.&lt;/li&gt;
&lt;li&gt;Arrays represent multiple data items of the same type using a single name.&lt;/li&gt;
&lt;li&gt;Arrays are used to implement the other data structures like linked lists, stacks, queues, trees, graphs, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Disadvantages of Array:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;As arrays have a fixed size, once the memory is allocated to them, it cannot be increased or decreased, making it impossible to store extra data if required. An array of fixed size is referred to as a static array. &lt;/li&gt;
&lt;li&gt;Allocating less memory than required to an array leads to loss of data.&lt;/li&gt;
&lt;li&gt;An array is homogeneous in nature, so a single array cannot store values of different data types. &lt;/li&gt;
&lt;li&gt;Arrays store data in contiguous memory locations, which makes deletion and insertion very difficult to implement. This problem is overcome by implementing linked lists, which allow elements to be accessed sequentially.
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Applications of Array:
&lt;/h2&gt;

&lt;p&gt;They are used in the implementation of other data structures such as array lists, heaps, hash tables, vectors, and matrices.&lt;br&gt;
Database records are usually implemented as arrays.&lt;br&gt;
It is used in lookup tables by computer.&lt;/p&gt;
&lt;h2&gt;
  
  
  Dynamic Arrays
&lt;/h2&gt;
&lt;h2&gt;
  
  
  What is ArrayList?
&lt;/h2&gt;

&lt;p&gt;An &lt;code&gt;ArrayList&lt;/code&gt; in Java is a resizable array-like data structure provided by the &lt;code&gt;java.util&lt;/code&gt; package. It implements the &lt;code&gt;List&lt;/code&gt; interface and extends the &lt;code&gt;AbstractList&lt;/code&gt; class, making it a part of the Java Collections Framework. Unlike regular arrays, &lt;code&gt;ArrayList&lt;/code&gt; can dynamically resize itself as elements are added or removed.&lt;/p&gt;

&lt;p&gt;Here are some key characteristics of &lt;code&gt;ArrayList&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resizable&lt;/strong&gt;: Unlike arrays, which have a fixed size, &lt;code&gt;ArrayList&lt;/code&gt; can dynamically grow or shrink in size as elements are added or removed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ordered Collection&lt;/strong&gt;: &lt;code&gt;ArrayList&lt;/code&gt; maintains the order of elements in which they are inserted. You can access elements by their index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allows Duplicates&lt;/strong&gt;: &lt;code&gt;ArrayList&lt;/code&gt; can contain duplicate elements. It preserves the insertion order, so elements can be added and accessed based on their position.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Indexed Access&lt;/strong&gt;: You can access elements in an &lt;code&gt;ArrayList&lt;/code&gt; using their index. This allows for efficient retrieval and modification of elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backed by Array&lt;/strong&gt;: Internally, an &lt;code&gt;ArrayList&lt;/code&gt; is backed by an array. When the array's capacity is reached, &lt;code&gt;ArrayList&lt;/code&gt; automatically resizes the underlying array to accommodate more elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Iterating Over Elements&lt;/strong&gt;: &lt;code&gt;ArrayList&lt;/code&gt; provides various methods to iterate over its elements, including traditional loops, enhanced for loops, and iterators.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's a basic example of using &lt;code&gt;ArrayList&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.ArrayList;

public class ArrayListExample {
    public static void main(String[] args) {
        // Create a new ArrayList
        ArrayList&amp;lt;Integer&amp;gt; numbers = new ArrayList&amp;lt;&amp;gt;();

        // Add elements to the ArrayList
        numbers.add(10);
        numbers.add(20);
        numbers.add(30);

        // Print the ArrayList
        System.out.println("ArrayList: " + numbers);

        // Accessing elements
        int value = numbers.get(1);
        System.out.println("Element at index 1: " + value);

        // Size of the ArrayList
        System.out.println("Size of the ArrayList: " + numbers.size());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ArrayList&lt;/code&gt; is widely used in Java for its flexibility, ease of use, and dynamic resizing capabilities, making it a versatile choice for storing and manipulating collections of elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  ArrayList Functions
&lt;/h2&gt;

&lt;p&gt;ArrayList functions, also known as methods, are built-in operations provided by the &lt;code&gt;ArrayList&lt;/code&gt; class in Java. These methods enable you to perform various operations on ArrayLists, such as adding, removing, searching, sorting, and iterating over elements. Here are some commonly used ArrayList functions in Java:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Adding Elements&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;add(E e)&lt;/code&gt;: Adds the specified element to the end of the ArrayList.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add(int index, E element)&lt;/code&gt;: Inserts the specified element at the specified position in the ArrayList.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Removing Elements&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;remove(Object o)&lt;/code&gt;: Removes the first occurrence of the specified element from the ArrayList.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;remove(int index)&lt;/code&gt;: Removes the element at the specified position in the ArrayList.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Accessing Elements&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;get(int index)&lt;/code&gt;: Returns the element at the specified position in the ArrayList.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;set(int index, E element)&lt;/code&gt;: Replaces the element at the specified position in the ArrayList with the specified element.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Size and Capacity&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;size()&lt;/code&gt;: Returns the number of elements in the ArrayList.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isEmpty()&lt;/code&gt;: Returns true if the ArrayList is empty; otherwise, returns false.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ensureCapacity(int minCapacity)&lt;/code&gt;: Increases the capacity of the ArrayList, if necessary, to ensure that it can hold at least the specified number of elements.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Searching and Sorting&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;contains(Object o)&lt;/code&gt;: Returns true if the ArrayList contains the specified element; otherwise, returns false.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;indexOf(Object o)&lt;/code&gt;: Returns the index of the first occurrence of the specified element in the ArrayList; returns -1 if the element is not found.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sort(Comparator&amp;lt;? super E&amp;gt; c)&lt;/code&gt;: Sorts the elements of the ArrayList using the specified comparator.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Iterating Over Elements&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;forEach(Consumer&amp;lt;? super E&amp;gt; action)&lt;/code&gt;: Performs the given action for each element of the ArrayList until all elements have been processed or the action throws an exception.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;iterator()&lt;/code&gt;: Returns an iterator over the elements in the ArrayList.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Converting to Array&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;toArray()&lt;/code&gt;: Returns an array containing all of the elements in the ArrayList in proper sequence.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.ArrayList;

public class ArrayListFunctionsExample {
    public static void main(String[] args) {
        // Create an ArrayList
        ArrayList&amp;lt;Integer&amp;gt; numbers = new ArrayList&amp;lt;&amp;gt;();

        // Adding elements
        numbers.add(10);
        numbers.add(20);
        numbers.add(30);

        // Removing elements
        numbers.remove(Integer.valueOf(20));

        // Accessing elements
        int firstElement = numbers.get(0);

        // Size
        int size = numbers.size();

        // Sorting
        numbers.sort(null);

        // Iterating
        for (Integer number : numbers) {
            System.out.println(number);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Internal working of ArrayList
&lt;/h2&gt;

&lt;p&gt;An &lt;code&gt;ArrayList&lt;/code&gt; in Java dynamically manages an array internally to accommodate the addition or removal of elements. It automatically resizes its underlying array when needed, typically using a doubling strategy for capacity management. This allows for flexible storage of collections of elements with efficient random access and ensures fast element retrieval.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Dimensional ArrayList
&lt;/h2&gt;

&lt;p&gt;In Java, you can create a multi-dimensional ArrayList by nesting ArrayLists within each other. This allows you to create structures resembling matrices or grids with multiple dimensions. Here's how you can create and work with a multi-dimensional ArrayList:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.ArrayList;

public class MultiDimensionalArrayListExample {
    public static void main(String[] args) {
        // Create a 2D ArrayList
        ArrayList&amp;lt;ArrayList&amp;lt;Integer&amp;gt;&amp;gt; matrix = new ArrayList&amp;lt;&amp;gt;();

        // Add rows to the 2D ArrayList
        for (int i = 0; i &amp;lt; 3; i++) {
            ArrayList&amp;lt;Integer&amp;gt; row = new ArrayList&amp;lt;&amp;gt;();
            for (int j = 0; j &amp;lt; 3; j++) {
                row.add(i * 3 + j + 1); // Add elements to the row
            }
            matrix.add(row); // Add the row to the 2D ArrayList
        }

        // Accessing elements
        int value = matrix.get(1).get(2); // Accessing element at row 1, column 2
        System.out.println("Element at row 1, column 2: " + value);

        // Printing the 2D ArrayList
        for (ArrayList&amp;lt;Integer&amp;gt; row : matrix) {
            for (int element : row) {
                System.out.print(element + " ");
            }
            System.out.println();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We create a 2D ArrayList named &lt;code&gt;matrix&lt;/code&gt; by nesting ArrayLists within each other.&lt;/li&gt;
&lt;li&gt;We add rows to the 2D ArrayList using nested loops, where each row is an ArrayList containing integer elements.&lt;/li&gt;
&lt;li&gt;We access elements of the 2D ArrayList using the &lt;code&gt;get()&lt;/code&gt; method on both the outer and inner ArrayLists.&lt;/li&gt;
&lt;li&gt;We print the elements of the 2D ArrayList using nested loops to traverse each row and element within the rows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach allows you to create and manipulate multi-dimensional data structures using ArrayLists in Java. You can extend this concept to create 3D, 4D, or higher-dimensional ArrayLists by nesting ArrayLists further.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>coding</category>
      <category>java</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
