<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ummey Haani on Medium]]></title>
        <description><![CDATA[Stories by Ummey Haani on Medium]]></description>
        <link>https://medium.com/@ummey.haani28?source=rss-4aeac22a5cba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yqeuaJEDy_wSonIY2yy7AQ.jpeg</url>
            <title>Stories by Ummey Haani on Medium</title>
            <link>https://medium.com/@ummey.haani28?source=rss-4aeac22a5cba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:21:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ummey.haani28/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Does xv6 Need a Per-Process Kernel Page Table?]]></title>
            <link>https://medium.com/@ummey.haani28/why-does-xv6-need-a-per-process-kernel-page-table-14b8895bafb9?source=rss-4aeac22a5cba------2</link>
            <guid isPermaLink="false">https://medium.com/p/14b8895bafb9</guid>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Ummey Haani]]></dc:creator>
            <pubDate>Wed, 18 Nov 2026 09:13:21 GMT</pubDate>
            <atom:updated>2026-11-18T09:13:21.057Z</atom:updated>
            <content:encoded><![CDATA[<h4>How mapping user pages into a per-process kernel page table lets xv6 read user memory directly via the MMU.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jl8OKxAH6kh-F3Bv" /><figcaption>Photo by <a href="https://unsplash.com/@brechtcorbeel?utm_source=medium&amp;utm_medium=referral">Brecht Corbeel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When I was implementing lazy allocation, my error backtraces led me to memmove(). I didn’t initially understand why a page that existed in the user page table wasn’t accessible to the kernel.</p><h3>Why the kernel couldn’t access the user address</h3><p>Standard xv6 has one global kernel page table that the kernel uses when it is executing. The user process has a separate page table with its user-space mappings.</p><p>The confusing part for me was that a user virtual address could be completely valid in the process’s user page table but still not be valid when the kernel tried to access it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USy43Ib8B11ZIhU8eZpMkw.jpeg" /></figure><p>That was the part I initially missed: a mapping existing in a page table doesn’t mean that mapping is available to the CPU at that moment.</p><p>For example, if a user program calls write() with a buffer address, the kernel needs to read from that user address. But the kernel’s page table doesn’t contain the user’s mappings. So copyin() has to translate the user virtual address itself. It uses walkaddr() to walk the user page table in software, get the physical address for that virtual address, and then copy the data from that physical memory. If the requested buffer crosses a page boundary, copyin() repeats this for the next page.</p><h3>How the per-process kernel pagetable works</h3><p>With a per-process kernel page table, each process gets its own copy of the kernel page table. I then add that process’s user mappings to its kernel page table too.</p><p>So when that process is running in the kernel, its satp points to a page table containing both:</p><ul><li>the kernel mappings, and</li><li>the user mappings for that particular process.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRrN4RkrqXJTo5m9IJ1hKA.jpeg" /></figure><p>The important difference is that the user virtual address now exists in the page table that the CPU is actually using while the kernel is running.</p><p>That allows copyin() and copyinstr() to use the user virtual address directly, because the corresponding mapping now exists in the kernel page table currently being used by the CPU. The MMU then does the normal virtual-to-physical translation using the current satp page table.</p><h3>Keeping the two page tables synchronized</h3><p>When I was implementing lazy allocation, this mattered across the user-memory paths such as copyin(), copyout(), and copyinstr(). When a lazy-allocation path encounters a missing user page, my implementation allocates it and creates both mappings before doing the final memmove(). The important part was that both page tables needed to refer to the same physical page:</p><pre>pte_t *pte = walk(pagetable, va0, 0);<br>if(pte == 0 || (*pte &amp; PTE_V) == 0){<br>  mem = kalloc();<br>  mappages(pagetable, va0, PGSIZE, (uint64)mem, PTE_W|PTE_R|PTE_U);<br>  mappages(proc_kernel_pgtbl, va0, PGSIZE, (uint64)mem, PTE_W|PTE_R);<br>}</pre><p>The same physical page is mapped into both page tables. The user page table gets PTE_U, while the corresponding kernel mapping does not. That’s when it stopped feeling like just another copy of the kernel page table. It was another view of the same process’s memory that the kernel could use directly.</p><h3>The PTE permissions confused me too</h3><p>When I first mapped the user pages into the per-process kernel page table, I thought I could just copy the exact same PTE permissions from the user page table. That doesn’t work the way I originally thought. The part that matters is PTE_U.</p><p>In xv6, the user page table has PTE_U set on user-accessible mappings. But the kernel is running in supervisor mode, and in xv6’s normal configuration, the kernel is not allowed to access pages through a PTE with PTE_U bit set.</p><p>So when I created the corresponding mappings in the kernel page table, I needed to remove PTE_U. Then the kernel can use those mappings while running in supervisor mode, while the user process still uses the separate user page table with its own PTE_U permissions.</p><blockquote>The mapping in the user page table and the mapping of the same physical page in the kernel page table don’t have to use identical permission bits.</blockquote><h3>What does “mapping a page” actually mean?</h3><p>I thought the virtual address and physical address were added to the page table together as a new entry during mapping. But after working with walk() and mappages(), a virtual address isn’t stored as one giant value inside a page-table entry.</p><p>For Sv39, a virtual address is divided into three 9-bit page-table indices and a 12-bit page offset. The address breaks down into:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WHiyGPGh08Bwf8MeAF7XAw.jpeg" /></figure><p>The three indices tell the page-table walk which entries to follow at each level. Then, once the walk reaches the leaf PTE, that PTE contains the physical-page number and permission bits. The final 12 bits (for example, 0x050 in address 0x4050) are the offset within the 4 KiB page. Instead of selecting another page-table entry, it identifies which byte within the mapped physical page the virtual address refers to.</p><p>When mappages() maps a page, it follows the virtual address through the page-table levels and writes the physical page number and permissions into the leaf PTE that VA points to.</p><p>I stopped thinking:</p><blockquote><strong>VA + PA = one new entry somewhere</strong></blockquote><p>and started thinking:</p><blockquote><strong>VA → page-table indices → leaf PTE → physical page</strong></blockquote><h3>Allocation and mapping are two different things</h3><p>Allocation refers to kalloc() taking a physical page from the free list. kalloc() doesn’t care which virtual address that page will eventually represent. It just gives the kernel a physical page.</p><p>mappages() is what establishes the relationship between the virtual address and that physical page, by putting the physical page number and permission bits into the appropriate PTE.</p><p>That distinction became important during lazy allocation because a page can be allocated physically without yet being mapped to the virtual address I want. And a virtual address can be part of the process’s allowed address space without having a physical page allocated for it yet.</p><h3>What I actually learned</h3><p>Before implementing the per-process kernel page table, I mostly thought of page tables as something the MMU used in the background.</p><p>After this change, I started seeing the page table as something the kernel itself has to manage carefully. The page table being used by the CPU matters just as much as the memory itself.</p><blockquote>A physical page can exist, and a user page table can contain a valid mapping for it, but that doesn’t mean the kernel can access that virtual address through the page table currently installed in satp.</blockquote><p>Once I understood that, the per-process kernel page table finally made sense to me.</p><p><strong><em>Source:</em></strong> <a href="https://github.com/mit-pdos/xv6-riscv?">MIT’s xv6-riscv</a> source code and xv6 documentation. xv6-riscv is distributed under the MIT License.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14b8895bafb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Actually Happens When a User Program Calls sbrk() in xv6?]]></title>
            <link>https://medium.com/@ummey.haani28/what-actually-happens-when-a-user-program-calls-sbrk-in-xv6-1427753f7bc0?source=rss-4aeac22a5cba------2</link>
            <guid isPermaLink="false">https://medium.com/p/1427753f7bc0</guid>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ummey Haani]]></dc:creator>
            <pubDate>Sun, 15 Nov 2026 15:13:12 GMT</pubDate>
            <atom:updated>2026-11-15T15:13:12.760Z</atom:updated>
            <content:encoded><![CDATA[<h4>Tracing a single sbrk(100) system call from user space through ecall, the trampoline, the trapframe, and back.</h4><figure><img alt="Dark-mode dual-monitor coding desk setup illuminated with green ambient light" src="https://cdn-images-1.medium.com/max/1024/0*ikvuWz9UcyxC4OXG" /><figcaption>Photo by <a href="https://unsplash.com/@writecodenow?utm_source=medium&amp;utm_medium=referral">Boitumelo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When I first implemented lazy allocation in xv6, I thought sbrk(100) allocated 100 bytes immediately, but it doesn’t. That forced me to understand something deeper:</p><p>What actually happens between a user program calling a system call and the kernel handling it?</p><h3>Following an sbrk() call through xv6</h3><h4>1. A user program calls sbrk(100)</h4><p>The user-level sbrk() wrapper puts the system call number into a7 and puts 100 into a0. Then it executes ecall.</p><pre>sbrk:<br> li a7, SYS_sbrk<br> ecall<br> ret</pre><p>This causes the CPU to trap into supervisor mode. In xv6, the user trap path enters through uservec(), reaches usertrap(), and later returns through the trampoline.</p><h4>2. The trap enters uservec in trampoline.S</h4><p>Before entering user mode, xv6 sets up sscratch so that the trap entry code can use it to save the user’s registers safely.</p><p>When uservec starts, the user’s registers still contain the values from before the trap. The first part of the assembly saves the user’s a0 in sscratch, then uses a0 to get the trapframe address. It can then save the user’s registers into the trapframe, including the original a0.</p><p>So:</p><ul><li>the user’s original a0 contains the 100 argument.</li><li>uservec needs a register to work with the trapframe.</li><li>sscratch gives it a temporary place to save that original a0.</li><li>the original a0 is eventually stored in the trapframe.</li></ul><p>Here, the trapframe is a RAM structure where xv6 stores the user’s register state while the kernel is running.</p><p>Once the registers are saved, uservec switches to the kernel page table and enters usertrap().</p><h4>3. usertrap() figures out what happened</h4><p>In usertrap(), it checks r_scause of the trap. For a normal system call from user mode, r_scause is 8, which is the environment-call exception from user mode.</p><pre>if(r_scause() == 8)</pre><p>usertrap() advances the saved program counter so the sret return doesn’t execute the same ecall again. So this wasn’t a page fault or some other kind of trap. It was a syscall.</p><h4>4. The syscall dispatcher calls sys_sbrk()</h4><p>usertrap() recognizes the system call and calls syscall(). That dispatcher looks at the a7 value saved in the trapframe, which tells xv6 which system call the user program requested. In this case it identifies sbrk, so it calls sys_sbrk().</p><h4>5. sys_sbrk() changes p-&gt;sz</h4><p>sys_sbrk() gets the 100 argument from the saved syscall state a0 in the trapframe and increases p-&gt;sz, since 100 is positive and this is lazy allocation. On the other hand, if the argument is negative, xv6 has to shrink the process’s address space and deallocate the relevant memory.</p><p>So the process now has a larger virtual-address range, but the physical pages backing that range haven’t necessarily been allocated yet.</p><h4>6. The return value goes back into a0</h4><p>After the work is done, sys_sbrk() returns the old program size. The syscall dispatcher takes that value and puts it in the a0 slot of the trapframe. In xv6, the dispatcher literally assigns the result of the selected sys_* function to p-&gt;trapframe-&gt;a0.</p><p>The same a0 register holds the user argument before the call, and then it gets overwritten with the return value after the call.</p><blockquote>Before the syscall, a0 contains the argument.</blockquote><blockquote>After the syscall, a0 contains the return value.</blockquote><p>Then the call returns toward user mode. usertrap() prepares the return: xv6 needs to restore the user’s register state from the trapframe and return to the user page table.</p><h4>7. The kernel returns through the trampoline</h4><p>The return path goes back through the trampoline. The user page table is restored, while the trapframe remains available at its fixed virtual address so the trampoline can reload the user’s registers. The trampoline restores the registers from the trapframe, including the a0 value that now contains the return value from sbrk().</p><h4>8. sret returns to user mode</h4><p>At last, sret is called to return to user mode. The CPU continues executing the user program after the original ecall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VpYgeuCMWT9E8va2ncVTCQ.jpeg" /></figure><p>The process now has a larger virtual-address range, but the physical page isn’t necessarily present yet.</p><p>If the user process next puts something in that lazily allocated memory, the CPU will page fault because there is no valid physical mapping for that virtual address yet. usertrap() will catch the fault, the lazy-allocation code allocates a physical page with kalloc(), maps it into the process’s page table, and then the process can continue.</p><h3>What I actually learned</h3><p>Following one sbrk(100) call, I had to put together pieces I had not really connected before: the syscall wrapper, ecall, trap entry, the trapframe, syscall dispatch, and the later page fault.</p><blockquote>With lazy allocation, sbrk() can expand the process’s virtual address space and leave the physical allocation until the process actually needs the memory.</blockquote><p>That is when lazy allocation clicked for me.</p><p><strong><em>Source:</em></strong><em> </em>This article uses code from<a href="https://github.com/mit-pdos/xv6-riscv?"> MIT’s xv6-riscv</a>, which is distributed under the MIT License.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1427753f7bc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Broke xv6’s exec() by Using the Wrong Page-Table Checks]]></title>
            <link>https://medium.com/@ummey.haani28/i-broke-xv6s-exec-by-using-the-wrong-page-table-checks-d9e4f6d0db69?source=rss-4aeac22a5cba------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9e4f6d0db69</guid>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[operating-systems]]></category>
            <dc:creator><![CDATA[Ummey Haani]]></dc:creator>
            <pubDate>Fri, 13 Nov 2026 20:16:44 GMT</pubDate>
            <atom:updated>2026-11-15T15:01:56.779Z</atom:updated>
            <content:encoded><![CDATA[<h4>How a subtle mix-up between virtual address boundaries, walkaddr(), and walk() caused a silent init crash and a mappages: remap panic.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*RcsD6spHzfsCZTJbYlgglg.jpeg" /></figure><blockquote><strong>Note:</strong> this article is based on the 2021 xv6 lazy-allocation work and my own modifications to xv6, including the guardpg_end checks and lazy handling in copyin()/copyinstr().</blockquote><p>I was debugging an xv6 lazy-allocation failure where init was exiting. I narrowed the failure down to copyinstr(), which was returning an error while copying a string from user space into the kernel. At first I couldn’t tell if the bug was in exec(), copyin(), or copyinstr(). After some debug prints it was copyinstr().</p><p>The error happened before the shell was launched. That eventually caused the init process to exit, and made it look like exec() was broken. To find out why, I had to look past exec() and into how memory mapping worked: guard pages, virtual address boundaries, and why walkaddr() and walk() are not the same thing.</p><h3>The first mistake: assuming every process has a guard page</h3><p>I had added lazy-allocation checks to copyin() and copyinstr(). My copyin() and copyinstr() checks assumed that anything at or below guardpg_end should be rejected. So my original check was:</p><pre>if(va0 &lt;= p-&gt;guardpg_end || va0 &gt;= p-&gt;sz)<br>  return -1;</pre><p>But this was the problem that was making my /init program exit.</p><p>Here, the guard page is the stack guard page created as part of the exec() stack setup. But it isn’t there in the initial initcode address space in the same way. My check treated guardpg_end == 0 as if it were a real boundary, so an address like 0 could be rejected before the process had even reached the point where that guard page existed. In my trace, copyinstr() was being asked to read from virtual address 0. At this point the system hadn’t even launched the shell yet, so this wasn’t a shell exec() failing. My guard-page check was rejecting virtual address 0 in the initial initcode address space.</p><p>copyinstr() returned an error, which caused the operation using it to fail. That eventually caused init to exit. It looked like exec() was broken, but the failure was earlier in copyinstr().</p><blockquote>When a process dies during exec(), the bug doesn’t have to be inside exec() itself.</blockquote><h3>Fixing the first boundary check</h3><p>After exec() builds the new user stack, the process does have a guard page, so I needed to check whether one had actually been created. This was my revised code:</p><pre>if((p-&gt;guardpg_end &gt; 0 &amp;&amp; va0 &lt;= p-&gt;guardpg_end) || va0 &gt;= p-&gt;sz)<br>  return -1;</pre><p>That stopped treating guardpg_end == 0 as a real guard page boundary. But I still got:</p><pre>Rejected by guardpg: va0=0x0000000000000000, guard=0x0000000000002000<br>Rejected by guardpg: va0=0x0000000000000000, guard=0x0000000000002000<br>Rejected by guardpg: va0=0x0000000000000000, guard=0x0000000000002000<br>panic: mappages: remap</pre><p>So that check wasn’t the whole bug. I had to look at what the guard page actually was. guardpg_end only identifies the end of the guard-page range. It doesn’t mean every lower virtual address should be rejected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*7t0FEANSXsqZRXc7_oseow.jpeg" /></figure><p>I was treating guardpg_end as the start of the usable user range, and I only checked whether the virtual address was below that.</p><p>A guard page is a specific virtual address range exactly one PGSIZE wide. I shouldn’t reject every address below guardpg_end, only the ones that actually land inside the guard page.</p><p>I changed the check to:</p><pre>uint64 guardpg_start = p-&gt;guardpg_end - PGSIZE;<br>if(p-&gt;guardpg_end &gt; 0 &amp;&amp; (va0 &lt; p-&gt;guardpg_end &amp;&amp; va0 &gt;= guardpg_start)){<br>  printf(&quot;Rejected by guardpg: va0=%p, guard=%p\n&quot;, va0, p-&gt;guardpg_end);<br>  return -1;<br>}</pre><p>I had added my own guardpg_end tracking to xv6 while implementing the lazy-allocation checks. That limited the rejection to the actual guard-page range. The rejected-by-guard-page prints went away. But the remap panic didn’t. To solve it, I kept tracing the address.</p><h3>The second mistake: using walkaddr() to decide whether a page exists</h3><p>Later in the lazy-allocation code I had something like:</p><pre>if(walkaddr(pagetable, va0) == 0){<br>  //allocate a page and map it<br>}</pre><p>I was using that to decide if the virtual address needed a new physical page allocated.</p><p>walkaddr() does not just mean “does this virtual address have a PTE?”</p><p>In xv6, walkaddr() only returns a physical address when the PTE is valid and has PTE_U set, i.e. the mapping is accessible from user mode.</p><p>So a 0 return from walkaddr() doesn’t necessarily mean that no PTE exists. It can also mean that the PTE isn’t a valid user mapping. That mattered because the guard page can have a valid PTE without being a user-accessible mapping. If walkaddr() returned 0, my code would allocate and map anyway, even if the guard page was already there. Then mappages() found that the target PTE was already valid and panicked with:</p><pre>panic: mappages: remap</pre><p>mappages() wasn’t broken. I was handing it an address that should never have gone down the allocate-and-map path.</p><h3>walk() gave me the information I actually needed</h3><p>I needed the PTE, not the physical address. So I changed it to:</p><pre>pte_t *pte = walk(pagetable, va0, 0);<br>if(pte == 0 || (*pte &amp; PTE_V) == 0){<br>  //allocate a page and map it<br>}</pre><p>walk() gave me the PTE so I could check its flags directly. In this case of allocating pages, I wanted to check when there was no PTE or the existing PTE wasn’t valid. That was different from walkaddr(), which also requires the mapping to have PTE_U. That’s why walkaddr() was the wrong call for what I was asking. I wasn’t asking “what physical address does this user mapping point to?” I was asking “what kind of PTE is at this virtual address?” walk() answers that.</p><h3>What I originally thought was wrong</h3><p>While debugging, I also suspected my per-process kernel page table was getting corrupted during exec(), because I had modified copyin()/copyout() for lazy allocation. After I traced the remap, I found that the panic was actually caused by the walkaddr() check.</p><p>I started with a boundary check in copyin()/copyinstr(). Fixing it exposed a second problem: I was using walkaddr() to decide whether a mapping existed, even though walkaddr() deliberately rejects mappings without PTE_U. The useful lesson for me was that:</p><blockquote>page-table debugging got easier once I stopped treating “unmapped,” “mapped,” and “user-accessible” as the same thing.</blockquote><p>The final bug wasn’t really inside exec(). My page-table and address-validation checks were causing exec() to fail.</p><p><strong><em>Source:</em></strong><em> </em>This article uses code from <a href="https://github.com/mit-pdos/xv6-riscv?">MIT’s xv6-riscv</a>, which is distributed under the MIT License.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9e4f6d0db69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How JavaScript Makes Websites Dynamic]]></title>
            <link>https://medium.com/@ummey.haani28/how-javascript-makes-websites-dynamic-f626b4a7add0?source=rss-4aeac22a5cba------2</link>
            <guid isPermaLink="false">https://medium.com/p/f626b4a7add0</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[learning-code]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ummey Haani]]></dc:creator>
            <pubDate>Fri, 23 May 2025 14:32:08 GMT</pubDate>
            <atom:updated>2026-11-13T19:31:56.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*ojNYz7UlnuVvnCgz16OoRg.jpeg" /></figure><h3>💡 What Does “Dynamic” Mean?</h3><p>A <strong>dynamic website</strong> changes when you interact with it. It’s not just about looking pretty with pictures and colors (that’s HTML and CSS!). It’s about the website <strong>reacting</strong> to what you do.</p><ul><li>When you click a button, something happens, like a message showing up.</li><li>You type something into a form, and the website checks your input or updates a list.</li><li>Maybe you scroll down, and more information appears on the page — <strong>without reloading the whole website</strong>.</li></ul><p>This is all JavaScript’s <strong>magic</strong> 🔮 — it makes websites interactive, smart, and fun to use!</p><h3>🕵️‍♀️ Let’s Reverse Engineer It!</h3><p>Before JavaScript, websites were <strong>static</strong>. That means:</p><ul><li>They showed the same content to everyone.</li><li>They didn’t change unless you loaded a new page.</li></ul><p>But with <strong>JavaScript</strong>, you can change things on the page <strong>without reloading it</strong>. JavaScript lets you <strong>add behavior</strong> to HTML elements.</p><p><strong>Here’s how you can make a webpage dynamic:</strong></p><ol><li><strong>HTML</strong> sets up the structure (like the text and buttons).</li><li><strong>CSS</strong> makes it look pretty (like colors and sizes).</li><li><strong>JavaScript</strong> adds functionality (it makes the page “do” things like change text when you click a button).</li></ol><h3>🧪 Let’s Do It: Interactive Example (No Install Needed!)</h3><p>Try this code on <a href="https://jsfiddle.net/">jsfiddle.net</a> or <a href="https://codepen.io/">codepen.io</a>. Just follow the steps!</p><h3>🔹 Step 1: Set Up HTML (Structure)</h3><pre>&lt;p id=&quot;message&quot;&gt;Welcome!&lt;/p&gt; <br>&lt;button onclick=&quot;updateMessage()&quot;&gt;Click Me&lt;/button&gt;</pre><p><strong>Explanation:</strong></p><ul><li>&lt;p id=&quot;message&quot;&gt;Welcome!&lt;/p&gt;: This is a <strong>paragraph</strong> with the text &quot;Welcome!&quot; inside. It also has an <strong>ID</strong> (&quot;message&quot;), which makes it easy to find with JavaScript.</li><li>&lt;button onclick=&quot;updateMessage()&quot;&gt;Click Me&lt;/button&gt;: This is a <strong>button</strong> that says &quot;Click Me.&quot; The onclick is an <strong>event</strong> — it means, “When the button is clicked, run this JavaScript function.”</li></ul><h3>🔹 Step 2: Add the JavaScript (Behavior)</h3><pre>function updateMessage() { <br>  document.getElementById(&quot;message&quot;).innerHTML = &quot;You clicked the button!&quot;; <br>}</pre><p><strong>Explanation:</strong></p><ul><li>function updateMessage() { ... }: This is a <strong>JavaScript function</strong> called updateMessage. A function is a block of code that runs when you call it.</li><li>document.getElementById(&quot;message&quot;): This finds the <strong>HTML element</strong> (the paragraph) with the ID &quot;message&quot;. It’s like saying, “Find the thing on the page that’s called ‘message’.”</li><li>.innerHTML = &quot;You clicked the button!&quot;: This changes the content inside the paragraph. It replaces &quot;Welcome!&quot; with &quot;You clicked the button!&quot; when the button is clicked.</li></ul><h3>🔹 Step 3: Run the Code and See It Live</h3><ul><li>Click <strong>Run</strong> ▶ on jsFiddle or CodePen, and click the button.</li><li>The paragraph’s text will change to “You clicked the button!” without the whole page reloading.</li></ul><p>This is <strong>JavaScript in action</strong>! It’s updating the page dynamically — making the page interact with you.</p><h3>🧠 What’s Really Happening Behind the Scenes?</h3><p>Let’s break it down:</p><ol><li><strong>HTML</strong>: The basic structure of your webpage.</li><li><strong>CSS</strong>: (Not used here, but imagine it styles the button and text).</li><li><strong>JavaScript</strong>: Adds functionality to the page</li></ol><ul><li>You tell JavaScript: “When the button is clicked, update the paragraph with new text.”</li><li>JavaScript reacts <strong>when the user clicks the button</strong> — that’s called an <strong>event</strong>.</li></ul><p><strong>Events in JavaScript:</strong></p><ul><li>An event happens when something occurs on the page — like clicking a button, pressing a key, or even moving the mouse over an element.</li><li>You can tell JavaScript: “When this event happens, do <strong>this</strong> thing.”</li></ul><p>In the example, the event is the <strong>click</strong> on the button, and <strong>what happens</strong> is the text inside the paragraph changes.</p><h3>💥 Why Is This So Cool?</h3><p>JavaScript makes websites <strong>dynamic</strong> because:</p><ul><li>You don’t have to reload the page every time you want to change something.</li><li>It reacts to the user, making websites feel alive and <strong>responsive</strong>.</li><li>It can change things like text, images, buttons, or even background colors in real-time.</li></ul><h3>🚀 What Can You Do With JavaScript?</h3><p><strong>1. Interact with Users:</strong></p><ul><li>You can listen for when a user clicks something, types something, or scrolls through a page.</li></ul><p><strong>2. Real-Time Updates:</strong></p><ul><li>For example, imagine you’re typing a comment on a blog. JavaScript can <strong>automatically</strong> show you your comment as you type without needing to click a submit button.</li></ul><p><strong>3. Fetch Data Without Reloading:</strong></p><ul><li>JavaScript can grab information from the internet (like weather updates) and display it on your page without refreshing it. This makes your page <strong>faster</strong> and smoother.</li></ul><h3>💬 Your Challenge:</h3><ul><li>Play with the button! Try changing the text to something else like “I clicked again!” or “Hello, world!”</li><li>Add another button that changes the color of the paragraph instead of just the text. Use JavaScript to change the style property!</li></ul><p>Remember, the best way to learn is by <strong>experimenting</strong> and making mistakes. Keep playing with JavaScript until it feels natural.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f626b4a7add0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Essentials: Part 1 — Learn the Logic, Not Just the Code]]></title>
            <link>https://medium.com/@ummey.haani28/javascript-essentials-part-1-learn-the-logic-not-just-the-code-fb4ba54cf0a9?source=rss-4aeac22a5cba------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb4ba54cf0a9</guid>
            <category><![CDATA[javascript-basics]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding-tutorial]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Ummey Haani]]></dc:creator>
            <pubDate>Thu, 22 May 2025 09:53:09 GMT</pubDate>
            <atom:updated>2026-11-13T19:27:34.363Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript Essentials: Part 1 — Learn the Logic, Not Just the Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*gYQ-qEHOh8pbIOB0BDLCnQ.jpeg" /></figure><p>Most JS beginners make the same mistake: they try to remember syntax without understanding the logic.</p><p>In this article, I break down the first key concepts in JavaScript clearly — no tutorials, no noise.</p><p>By the end of this, you’ll know how variables, functions, DOM and events work; and how to debug with console.log() the right way.</p><p>Let’s go →</p><h3>🌟 JavaScript Essentials (Part 1)</h3><p><strong>Get familiar with JavaScript and create your own interactive websites — right in your browser!</strong></p><p><strong>📦 Tools:</strong> Just your browser — no setup needed<br> <strong>🧠 Skill Level:</strong> Total Beginner<br> <strong>⏱ Time:</strong> ~30 minutes</p><h3>👋 What Is JavaScript?</h3><p>JavaScript makes websites interactive. Without it, a site just sits there. With JavaScript, it can <strong>react to clicks</strong>, <strong>change content</strong>, <strong>show popups</strong>, or even <strong>build games</strong>.</p><p>Today, you’ll learn how to:</p><ul><li>Store information</li><li>Make your page respond to clicks</li><li>Change text on a webpage</li><li>Understand what’s going on behind the scenes</li></ul><h3>🧱 Step 1: What Is a Variable?</h3><p>A variable is like a <strong>box</strong> that stores something you want to use later.</p><h3>🧪 Try it in your browser console:</h3><ol><li>Open any webpage</li><li>Right-click &gt; <strong>Inspect</strong></li><li>Go to the <strong>Console</strong> tab</li><li>Paste this:</li></ol><pre>let name = &quot;Zara&quot;;<br>let age = 12;<br><br>console.log(&quot;Hi! My name is &quot; + name + &quot; and I’m &quot; + age + &quot; years old.&quot;);</pre><h3>🔍 What’s Happening?</h3><ul><li>let name = &quot;Zara&quot;; → creates a variable named name</li><li>let age = 12; → creates a variable named age</li><li>console.log(...) → shows a message using both variables</li></ul><p>✅ <strong>Tip:</strong><br> Use let to create a new variable.<br> Use console.log() to test your code.</p><h3>✨ Step 2: What Is a Function?</h3><p>A <strong>function</strong> is like a recipe — a set of steps you can run anytime.</p><h3>🧪 Try this in the console:</h3><pre>function sayHello() {<br>  alert(&quot;Hello, world!&quot;);<br>}<br><br>sayHello();</pre><h3>🔍 Breakdown:</h3><ul><li>function sayHello() { ... } → defines a function</li><li>alert(&quot;Hello, world!&quot;); → shows a popup</li><li>sayHello(); → runs the function</li></ul><p>✅ <strong>Tip:</strong><br> Functions help you <strong>reuse</strong> code. You can call them again and again.</p><h3>🔔 Step 3: What Is an Event?</h3><p>An <strong>event</strong> is something that happens — like a button click or key press. JavaScript lets you say: “When this happens, do this.”</p><h3>📄 Step-by-Step in a Free Online Editor:</h3><ol><li>Go to <a href="https://jsfiddle.net/">jsfiddle.net</a> (or use <a href="https://codepen.io/">codepen.io</a>)</li><li>Paste this code in the HTML &amp; JavaScript sections:</li></ol><pre>// This function changes the text inside the paragraph with id &quot;myText&quot; <br><br>function changeText() { <br>  document.getElementById(&quot;myText&quot;).innerHTML = &quot;You clicked the button!&quot;; <br>}</pre><p>Then use this button in your HTML to trigger the function:</p><pre>&lt;button onclick=&quot;changeText()&quot;&gt;Click me&lt;/button&gt; <br>&lt;p id=&quot;myText&quot;&gt;Hello, world!&lt;/p&gt;</pre><h3>🔍 What’s Happening?</h3><ul><li>&lt;button onclick=&quot;changeText()&quot;&gt;Click me&lt;/button&gt; → runs changeText() when clicked</li><li>&lt;p id=&quot;myText&quot;&gt;Hello, world!&lt;/p&gt; → text that will change</li><li>changeText() → finds the paragraph and changes the text</li></ul><p>✅ <strong>Tip:</strong><br> You can also use events like onmouseover, onkeydown, or onchange.</p><h3>🌐 Step 4: What Is the DOM?</h3><p><strong>DOM</strong> = the whole webpage, but in a form JavaScript can understand.</p><p>JavaScript uses the DOM to <strong>find and change</strong> things on the page.</p><h3>🧪 Full Example:</h3><pre>&lt;p id=&quot;myText&quot;&gt;Hi there!&lt;/p&gt;<br>&lt;button onclick=&quot;changeText()&quot;&gt;Click me!&lt;/button&gt;<br><br>&lt;script&gt;<br>  function changeText() {<br>    document.getElementById(&quot;myText&quot;).innerHTML = &quot;You clicked the button!&quot;<br>  }<br>&lt;/script&gt;</pre><h3>🔍 Line-by-Line Explanation:</h3><ul><li>id=&quot;myText&quot; → gives the element a label</li><li>onclick=&quot;changeText()&quot; → runs the function on click</li><li>document.getElementById(...) → finds the element</li><li>.innerHTML = &quot;...&quot; → replaces the content</li></ul><h3>🔁 What You Can Try Next:</h3><ul><li>Change the text in the paragraph</li><li>Change the button label</li><li>Add another button that does something different</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb4ba54cf0a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>