<?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 Sheryar Amir on Medium]]></title>
        <description><![CDATA[Stories by Sheryar Amir on Medium]]></description>
        <link>https://medium.com/@dev.sheryaramir?source=rss-13ea9a0bdc88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3CbwwGGsNNaCCIp4ojaiSQ.jpeg</url>
            <title>Stories by Sheryar Amir on Medium</title>
            <link>https://medium.com/@dev.sheryaramir?source=rss-13ea9a0bdc88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:29:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dev.sheryaramir/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[Zod for Validation, Axios for Communication: A Perfect API Strategy]]></title>
            <link>https://medium.com/@dev.sheryaramir/zod-for-validation-axios-for-communication-a-perfect-api-strategy-3743d333e61b?source=rss-13ea9a0bdc88------2</link>
            <guid isPermaLink="false">https://medium.com/p/3743d333e61b</guid>
            <category><![CDATA[axios]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[zod]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Sheryar Amir]]></dc:creator>
            <pubDate>Tue, 10 Jun 2025 08:43:59 GMT</pubDate>
            <atom:updated>2025-06-10T08:43:59.053Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-vy5XJ5oFe1vfmAFE2O3jQ.jpeg" /></figure><p>In the world of web development, we often come across tools that make our lives easier. Two such popular tools are Axios and Zod. They serve different purposes but are often used together to build reliable, secure, and smooth web applications.</p><h3>1. What Are Axios and Zod?</h3><h4>Axios: What It Is and Where We Use It</h4><p>Axios is a JavaScript library used to send and receive data from servers. Think of it as a messenger between your application and the server. For example, when you click “Submit” on a form, Axios helps send that data to the backend.</p><p><strong>Use cases:</strong></p><ul><li>Sending login or signup information</li><li>Getting product lists from a server</li><li>Updating user profiles</li></ul><h4>Zod: What It Is and Where We Use It</h4><p>Zod is a TypeScript-first schema validation library. In simple terms, it checks if the data is correct before we use it. For example, if your form requires an email, Zod makes sure the user actually enters a valid email.</p><p><strong>Use cases:</strong></p><ul><li>Form validation</li><li>API response validation</li><li>Checking user input before sending it to the backend</li></ul><h3>2. What Are the Benefits of Using Axios and Zod?</h3><p><strong>Axios:</strong></p><ul><li>Simple to use and beginner-friendly</li><li>Handles requests and responses cleanly</li><li>Built-in support for error handling and timeouts</li></ul><p><strong>Zod:</strong></p><ul><li>Prevents bad data from breaking your app</li><li>Helps catch bugs early</li><li>Easy to integrate with other tools like React, Next.js, and TypeScript</li></ul><h4>3. Why These Technologies Make Life Simple</h4><p>Imagine you’re building a house:</p><ul><li>Axios is like your delivery truck — it brings in supplies (data) from different places.</li><li>Zod is your quality inspector. It checks every item to ensure it’s the right size and not broken.</li></ul><p>Together, they ensure your project is built with the right materials and functions smoothly. They save time, reduce errors, and make your app more reliable.</p><pre> // Import Axios and Zod<br>import axios from &#39;axios&#39;;<br>import { z } from &#39;zod&#39;;<br><br>// 1. Define Zod schema for the user input you want to send<br>const CreateUserSchema = z.object({<br>  name: z.string().min(3, &#39;Name must be at least 3 characters&#39;),<br>  email: z.string().email(&#39;Invalid email format&#39;),<br>});<br><br><br>// 2. Define your async function<br>async function createUser(data: unknown) {<br><br>  try {<br>    // 3. Validate input data with Zod<br>    const validatedData = CreateUserSchema.parse(data);<br><br>    // 4. Send valid data via Axios POST request<br>    const response = await axios.post(&#39;https://example/user&#39;, validatedData);<br><br>    console.log(&#39;User created:&#39;, response.data);<br><br>  } catch (error) {<br>    if (error instanceof z.ZodError) {<br>      console.error(&#39; Validation Error:&#39;, error.errors);<br>    } else {<br>      console.error(&#39; Axios or Network Error:&#39;, error);<br>    }<br>  }<br>}<br><br>// 5. Example usage with valid and invalid data<br>const userInput = {<br>  name: &#39;John Doe&#39;,<br>  email: &#39;john.doe@example.com&#39;,<br>};<br><br>createUser(userInput);</pre><h4><strong>4. What Do We Suggest to Young Developers?</strong></h4><p>If you’re just getting started:</p><ul><li>Use Axios to connect to APIs — it’s easier than using raw fetch and comes with helpful features.</li><li>Learn Zod to validate your data — it’s a lifesaver when things go wrong.</li><li>Don’t just rely on front-end validations — clean data is key to building secure and professional apps.</li></ul><p>Combine Axios and Zod to validate API responses after fetching them. This adds a powerful layer of protection to your app!</p><h4>Final Thoughts</h4><p>Even if you’re not a developer but work with websites or apps, understanding how tools like Axios and Zod work gives you more clarity. These tools aren’t just for tech experts — they’re designed to make everyone’s life easier by ensuring data is correct and communication between systems is smooth.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3743d333e61b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Node.js]]></title>
            <link>https://medium.com/@dev.sheryaramir/introduction-to-node-js-fc8d4d0d1cf6?source=rss-13ea9a0bdc88------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc8d4d0d1cf6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[v8-engine]]></category>
            <category><![CDATA[serverside-rendering]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sheryar Amir]]></dc:creator>
            <pubDate>Fri, 30 May 2025 19:40:33 GMT</pubDate>
            <atom:updated>2025-05-30T19:40:33.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ev-O2WyfqKTI54RhV7ODhA.png" /></figure><p>In today’s digital world, most websites and applications we interact with, from social media platforms to online shopping sites, need to work fast, respond in real time, and handle thousands (or even millions) of users simultaneously. Behind many of these experiences is a powerful technology called <strong>Node.js</strong>.</p><p>Whether you’re a non-technical business owner, a beginner developer, or just curious about how the web works, this article will help you understand what <strong>Node.js</strong> is, how it works, and why it’s so widely used.</p><h3>What Exactly is Node.js?</h3><p>At its core, <strong>Node.js</strong> is an <strong>open-source, cross-platform runtime environment</strong> that allows developers to run <strong>JavaScript on the server-side</strong>, outside of the browser.</p><p><strong>In simpler terms:</strong><br>Node.js lets you use JavaScript to build the <strong>backend</strong> (the behind-the-scenes part) of websites and applications, not just the front-end (what users see).</p><p>Before Node.js, JavaScript could only run in the browser (like Chrome or Firefox). But with Node.js, you can use JavaScript to build the parts of an app that talk to databases, manage users, send notifications, and more.</p><h3>How Does Node.js Work?</h3><p>Node.js is built on <strong>Google’s V8 JavaScript engine</strong>, which is the same engine that powers the Chrome browser. It’s known for its <strong>speed</strong> and <strong>efficiency</strong>.</p><p>However, one of Node.js’s biggest strengths is its <strong>non-blocking, event-driven architecture</strong>.</p><p>Here’s a simple way to understand it:</p><h3>What Can You Build with Node.js?</h3><p>Node.js is used in a wide range of real-world applications. Here are just a few things developers use it for:</p><ul><li><strong>Real-time chat apps</strong> (like WhatsApp, Messenger)</li><li><strong>Streaming services</strong> (like Netflix)</li><li><strong>E-commerce platforms</strong> (like Shopify)</li><li><strong>API servers</strong> (for mobile or web apps)</li><li><strong>IoT apps</strong> (Internet of Things)</li><li><strong>Collaborative tools</strong> (like Google Docs)</li><li><strong>Backend for mobile apps</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z4B11BLwyFhC0yg0KmaO4g.jpeg" /></figure><h3>Who Uses Node.js?</h3><p>Big companies trust Node.js for its performance and reliability. Some popular examples include:</p><ul><li><strong>Netflix </strong>For fast startup time and scalability</li><li><strong>LinkedIn </strong>For efficient server-side operations</li><li><strong>Uber</strong> For real-time data and performance</li><li><strong>PayPal </strong>Unified language for front-end and back-end</li><li><strong>Trello </strong>For real-time collaboration</li></ul><h3>What Makes Node.js So Popular?</h3><p>Let’s look at the reasons why Node.js has become a go-to choice for developers:</p><p><strong>1. Single Language (JavaScript) for Everything</strong></p><p>You don’t need to learn two separate languages for front-end and back-end. One language, JavaScript, does it all.</p><p><strong>2. Fast and Lightweight</strong></p><p>Thanks to the V8 engine and non-blocking I/O, Node.js apps perform extremely well under heavy loads.</p><p><strong>3. Massive Ecosystem (NPM)</strong></p><p>Node.js comes with <strong>NPM</strong> (Node Package Manager), a library of over <strong>2 million reusable packages</strong> that make development faster and easier.</p><p><strong>4. Real-Time Capabilities</strong></p><p>Perfect for apps like messaging, games, and live tracking.</p><p><strong>5. Large Community and Support</strong></p><p>Node.js has a huge community, which means lots of tutorials, forums, and third-party tools.</p><h3>Example Use Case</h3><p>Let’s say you want to build a simple <strong>to-do list app</strong>. With Node.js, you can:</p><ul><li>Create a server to store tasks</li><li>Allow users to log in and manage their to-dos</li><li>Save tasks to a database</li><li>Send real-time updates if a task is completed by a teammate.</li></ul><p>And all of this can be done using <strong>JavaScript only</strong>, from start to finish.</p><h3>The Future of Node.js</h3><p>Node.js continues to grow and evolve. With the rise of <strong>microservices</strong>, <strong>serverless architecture</strong>, and <strong>real-time applications</strong>, Node.js is becoming more important than ever.</p><p>Plus, many modern frameworks like <strong>Next.js</strong>, <strong>NestJS</strong>, and tools like <strong>Express.js</strong> are built around or on top of Node.js.</p><h3>Conclusion</h3><p>Node.js has completely changed the way developers build backend applications. It’s fast, efficient, beginner-friendly, and used by some of the biggest companies in the world.</p><p>If you’re just getting into programming, or you’re running a business and want to understand the tech behind your product, <strong>Node.js is a term worth remembering</strong>.</p><p>It’s not just a buzzword — it’s the powerful engine driving the web forward.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc8d4d0d1cf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React vs Next.js: Boosting Performance and SEO for Web Apps]]></title>
            <link>https://medium.com/@dev.sheryaramir/react-vs-next-js-boosting-performance-and-seo-for-web-apps-042e4229e29c?source=rss-13ea9a0bdc88------2</link>
            <guid isPermaLink="false">https://medium.com/p/042e4229e29c</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[user-experience]]></category>
            <dc:creator><![CDATA[Sheryar Amir]]></dc:creator>
            <pubDate>Thu, 31 Oct 2024 19:18:52 GMT</pubDate>
            <atom:updated>2024-10-31T19:23:18.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcuqNZ-5JnpHZ1eKKyaZmQ.png" /></figure><p>React.js and Next.js are both widely used in front-end development, each serving unique needs. React.js, developed by Facebook, excels in building dynamic UIs, but as applications grow, its client-side rendering approach can impact performance and SEO. This is where Next.js comes into play, enhancing React with optimized rendering and built-in solutions for faster, more search-friendly applications.</p><h4><strong>Why Does React.js Face Performance Issues?</strong></h4><p>When you build an app with React.js, everything — including JavaScript, CSS, and HTML — compiles into a JavaScript bundle. This bundle is then loaded and run on the user’s browser. However, the resulting JavaScript file can become quite heavy if your app has several components and uses API calls or complex states. Here’s how this impacts the user experience:</p><ol><li><strong>Slower Initial Load Time:</strong> Before the page is fully functional, the browser must load and execute the JavaScript bundle. This means users may have to wait longer to see content.</li></ol><p>2<strong>. Delayed Data Fetching and Rendering:</strong> React hooks like useEffect starts fetching data from APIs after loading. The component re-renders once the data arrives, further increasing the time before users see a complete page.</p><p>3.<strong> Client-Side Rendering (CSR) Only:</strong> React runs only on the client side (in the browser). This architecture affects the speed and SEO of a page since search engines can’t always “see” the content in the initial HTML file.</p><p>These factors together create a longer waiting time, which impacts user experience and SEO negatively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*uHlgNqp1w27-p5M3xGFyfw.png" /></figure><h4>How Next.js Addresses React’s Challenges</h4><p>Next.js, built on top of React, introduces key optimizations by allowing Server-Side Rendering (SSR), Static Site Generation (SSG), and even edge functions. Here’s how it improves on React’s limitations:</p><ol><li><strong>Faster Initial Rendering with HTML and CSS:</strong> When you create a Next.js app, it fetches data during the build process and pre-renders pages into static HTML and CSS files. This way, when users land on your site, they immediately get an HTML page rather than waiting for JavaScript to load.</li><li><strong>Improved SEO:</strong> Since Next.js pre-renders pages, search engine bots can crawl your website more effectively, immediately seeing the static HTML and CSS. In contrast, a React-only app initially looks empty to bots, as they need to execute JavaScript to render content — often missing dynamic content entirely.</li><li><strong>Efficient Builds with Rust and Faster Bundling:</strong> Next.js uses a build tool built on Rust, a fast, memory-efficient language. This offers better performance for build and refresh speeds than React’s older build tool, Webpack.</li><li><strong>Support for SSR and CSR:</strong> Next.js allows you to combine Client-Side Rendering (CSR) with Server-Side Rendering (SSR), dynamically rendering content as needed. This flexibility enables you to customize the user experience by determining which content should be server-rendered and which should rely on the client.</li></ol><p><strong>5. Automatic Code Splitting:</strong> Next.js automatically splits the JavaScript bundles, loading only the code necessary for a specific page. This optimization results in smaller files and faster loading.</p><p>In short, while React is an excellent choice for dynamic UIs, Next.js enhances performance, SEO, and user experience by handling initial content rendering on the server side, serving up lighter pages, and enabling faster builds. This makes Next.js ideal for building modern, scalable web applications where speed and search visibility are top priorities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=042e4229e29c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Vs ReactJS in Web Development]]></title>
            <link>https://medium.com/@dev.sheryaramir/javascript-vs-reactjs-in-web-development-dff8fe2169b2?source=rss-13ea9a0bdc88------2</link>
            <guid isPermaLink="false">https://medium.com/p/dff8fe2169b2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[dom-vs-virtual-dom]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Sheryar Amir]]></dc:creator>
            <pubDate>Thu, 16 May 2024 06:15:09 GMT</pubDate>
            <atom:updated>2024-05-16T06:15:09.009Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*otX7kLCGpIcicuFB" /></figure><p>In the big world of web development, it’s important to know the difference between JavaScript and React.js. JavaScript has been around since the early days of the internet and is a flexible language that makes websites interactive. React.js is newer and changed how we make the look and feel of websites by organizing them into reusable parts called components.</p><p>As we start to learn about JavaScript and React.js, we’ll talk about where they came from, what they do, and how they’re different. We’ll cover the basics of JavaScript and how React.js makes building websites easier. Join us as we break down JavaScript and React.js for beginners in web development.</p><h3>A Short History of JavaScript and React JS</h3><p>JavaScript, often abbreviated as JS, was created by Brendan Eich at Netscape in 1995. Initially, it was named LiveScript but was later renamed JavaScript for marketing purposes. JavaScript was designed to add interactivity and dynamic behavior to web pages.</p><p>Over the years, JavaScript has evolved significantly. It has gone from primarily a client-side scripting language that can be used for both client- and server-side development. With the introduction of ECMAScript standards, JavaScript has seen regular updates, introducing new features and enhancements.</p><p>React.js, commonly known as React, is a JavaScript library for building user interfaces. Facebook developed it and was initially released in 2013. React was created to address the need for a more efficient way to build large-scale, dynamic web applications with complex user interfaces.</p><p>React focuses specifically on the view layer of web applications. It uses a component-based architecture, where UIs are composed of reusable and encapsulated components. React’s primary goal is to simplify building interactive user interfaces by providing a declarative and component-based approach.</p><h3>Differences Between JavaScript and React JS</h3><ul><li>JavaScript is a programming language used for various tasks, including creating both front-end and back-end functionalities. In contrast, React.js is specifically designed as a tool for building user interfaces within web applications.</li><li>JavaScript provides the core language features and syntax for writing code. At the same time, React.js abstracts away some of the complexities of DOM manipulation by providing a component-based architecture and a virtual DOM for efficient UI updates.</li><li>JavaScript is a foundational language for web development and has a broader scope, so learning it comprehensively can take time. React.js, on the other hand, has a more focused scope, making it easier to learn to build user interfaces.</li><li>JSX, or JavaScript XML, is a special language used in React.js. It lets developers mix HTML-like code with JavaScript, making it easier to create things like buttons and text boxes. When we build our React app, JSX turns into regular JavaScript behind the scenes, helping our code work smoothly.</li><li>React extends the concept of components further. Components in React are reusable, self-contained modules that render a part of the UI. They can be created as functional components (functions) or class components (ES6 classes). React encourages a component-based architecture where UIs comprise nested components, each responsible for a specific UI part.</li></ul><h3>DOM (Document Object Model) VS Virtual DOM (Document Object Mode)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ATJERuea89mJcHcn" /></figure><p>The <a href="https://medium.com/@dev.sheryaramir/diving-into-document-object-model-dom-manipulation-with-javascript-4734e9d98173">DOM</a> is like a map that shows the layout of an HTML document as a tree. data structure. It provides a programming interface for web documents, allowing JavaScript to access, manipulate, and update the content and structure of a webpage dynamically.</p><p>React introduced the concept of a Virtual DOM, which is a lightweight copy of the actual DOM. React’s reconciliation algorithm compares the Virtual DOM with the actual DOM and efficiently updates only the changed parts of the DOM. This approach improves performance by minimizing DOM manipulation operations.</p><h3>Data Flow in Javascript and React JS</h3><p>In traditional JavaScript development, DOM manipulation is done directly, often resulting in inefficient updates when multiple DOM elements change.</p><p>React renders components to the Virtual DOM. When the component state or props change, React reconciles the Virtual DOM with the actual DOM, updating only the necessary parts efficiently. This approach improves performance and makes UI updates predictable.</p><h3>Rendering in Javascript and React JS</h3><p>In JavaScript, data binding between the UI and application data often requires manual synchronization, leading to complex code and potential bugs.</p><p>React uses a unidirectional data flow model, where data flows from parent to child components via props. Changes in data trigger re-renders of components, ensuring that the UI reflects the current state of the application data.</p><h3>Conclusion</h3><p>JavaScript and React.js are like building blocks for websites. JavaScript has been around for a long time, doing many different web jobs. React.js is newer and helps make websites look and work better. Together, they are the foundation of modern web design, guiding us toward exciting new possibilities online.</p><h3>Frequently Asked Questions</h3><h4>Is it necessary to learn JavaScript before diving into React.js?</h4><p>Yes, it is highly recommended to have a good understanding of JavaScript before learning React.js. Since React.js is built with JavaScript and heavily relies on its syntax and features, having a solid foundation in JavaScript will make it much easier to grasp React.js concepts and effectively use the library to build user interfaces. Additionally, JavaScript knowledge is essential for handling data manipulation, event handling, and other core functionalities required in web development, which are also utilized in React.js applications.</p><h4>What are the benefits of using React.js for building user interfaces?</h4><p>The benefits of using React.js for building user interfaces include:</p><ul><li>Efficient rendering with Virtual DOM for faster performance.</li><li>Component-based architecture promotes code reusability and maintainability.</li><li>Declarative syntax simplifies UI development and enhances readability.</li><li>A large ecosystem with robust community support and extensive documentation.</li></ul><h4>What are the key differences between traditional DOM manipulation and React’s approach to rendering?</h4><p>Traditional DOM manipulation directly changes how the webpage looks and behaves. React.js, on the other hand, uses a clever method called the Virtual DOM to make updates faster. It figures out what needs to change and only updates those parts, making things work more smoothly. Also, React.js makes it easier to describe how the webpage should look and behave, rather than having to write out every little detail. And finally, React.js helps organize code into small, reusable pieces called components, which makes building websites easier and faster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dff8fe2169b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Compilers, Interpreters, Transpilers, and Polyfills in Modern Web Development]]></title>
            <link>https://medium.com/@dev.sheryaramir/understanding-compilers-interpreters-transpilers-and-polyfills-in-modern-web-development-2bf49567f80f?source=rss-13ea9a0bdc88------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bf49567f80f</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[transpile]]></category>
            <category><![CDATA[interpreters]]></category>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[polyfill]]></category>
            <dc:creator><![CDATA[Sheryar Amir]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 13:25:00 GMT</pubDate>
            <atom:updated>2024-04-16T08:20:57.005Z</atom:updated>
            <content:encoded><![CDATA[<p>In the vast landscape of programming, understanding the tools and concepts that power software development is essential for every developer. From compilers to transpilers, and from interpreters to polyfills, each plays a crucial role in shaping the way code is written, interpreted, and executed. In this comprehensive guide, we’ll delve into the world of programming tools, demystifying complex concepts and shedding light on their importance in modern web development.</p><p>A<strong> compiler</strong> is like a translator for computer programs. It takes the code you write in a programming language (like Python or C++) and translates it all at once into a form that the computer can understand, which is usually called machine code. It’s like translating a whole book from one language to another before you read it.</p><p>An <strong>interpreter,</strong> on the other hand, works more like a language tutor. Instead of translating the entire program at once, it goes through the code line by line, translating and executing each line as it goes. It’s like having someone translate a conversation for you as it happens.</p><p>Why They’re Important:</p><p>Both compilers and interpreters are crucial for making software because they help turn the human-readable code we write into instructions that computers can understand and execute. Without them, we wouldn’t be able to create the apps, games, websites, and other software that we use every day.</p><h4>Differences between Compiling and Interpreting</h4><p>The main difference between compiling and interpreting code is in how they process the code:</p><p>1. Compilation:</p><p>- Compilation translates the entire code into machine language all at once.</p><p>- The resulting executable file can be run independently without needing the original source code.</p><p>- Common in languages like C, C++, and Java (before it’s just-in-time compiled).</p><p>2. Interpretation:</p><p>- Interpretation processes the code line by line, executing each line as it goes.</p><p>- Requires the interpreter to be present to run the code.</p><p>- Common in languages like Python, JavaScript, and Ruby.</p><p><strong>interpreters</strong> provide immediate error feedback during runtime but may initially execute code slower. Compilers offer faster execution speeds and comprehensive error checking at compile time but may not catch all errors until runtime. The choice between the two depends on factors such as performance requirements, development preferences, and the specific needs of the project.</p><h4>Just-in-time (JIT) compilation</h4><p>Just-in-time (JIT) compilation refers to a technique used in programming languages where the code is compiled into machine code at runtime, just before it is executed. This is in contrast to ahead-of-time (AOT) compilation, where the code is compiled into machine code before it’s run.</p><p>JavaScript itself is not a “Just-in-time (JIT) language” in the same sense as Java or C#, which are languages specifically designed to work with JIT compilation. However, many JavaScript engines, including V8 (used in Google Chrome), SpiderMonkey (used in Firefox), and JavaScriptCore (used in Safari), employ JIT compilation techniques to execute JavaScript code efficiently.</p><h4>Transpilers and Polyfills</h4><p><strong>Transpiler</strong>s are libraries that convert JavaScript code from a modern syntax to a style that older browsers can understand. Transpiled code is not always that easy to read. OR A transpiler is a special piece of software that translates source code to another source code. It can parse (“read and understand”) modern code and rewrite it using older syntax constructs so that it’ll also work in outdated engines.</p><p>For example, JavaScript before the year 2020 didn’t have the “nullish coalescing operator ??”. So, if a visitor uses an outdated browser, it may fail to understand the code like height = height ?? 100.</p><p>A transpiler would analyze our code and rewrite it.</p><pre>height ?? 100 into (height undefined &amp;&amp; height !== null) ? height ? 100.</pre><pre>//Before running the transpiler<br>height = height ?? 100;<br>//After running the transpiler<br>height = (height !== undefined &amp;&amp; height !== null) ? height: 100;</pre><p>Now the rewritten code is suitable for older JavaScript engines.</p><p>A <strong>polyfill </strong>is a piece of code that we write to enable the use of new features in older versions of browsers that do not support them. For example, ES6 introduced many features such as map and filter, which are not supported by older browsers like Internet Explorer. To ensure that the code we write works seamlessly across all platforms, we can create polyfills.</p><pre>Code example po// Simple javascript code<br>let array=[1,2,3,4,5,6]<br>let result=array.includes(4)<br>console.log(result)// true<br>// polyfills code<br>array.prototype.includesPolyfill=function(element){<br>for( leti=0; i&lt;this.length; i++){<br>if(element===this[i]){<br>return true;<br>}<br>}<br>return false;<br>}lyfills</pre><h4>Describe transpilers and why they’re useful for modern web development</h4><p>. Cross-browser Compatibility: Transpilers allow developers to write code using the latest language features, libraries, and frameworks without worrying about compatibility issues with older browsers. By translating modern code into older versions of JavaScript, transpilers ensure that web applications can run smoothly across a wide range of browsers and devices.</p><ul><li>Ease of use: Transpilers allow developers to write code using the latest language features while ensuring that the code works on older engines. This enables developers to take advantage of the latest language improvements without worrying about compatibility issues.</li><li>Cross-platform compatibility: Transpilers can also be used to translate code from one programming language to another, enabling developers to write code in a language they are familiar with and then translate it to a different language for execution on a different platform. For example, a transpiler can translate TypeScript code into JavaScript code for execution in a web browser.</li></ul><h4>Diving into Babel and Webpack</h4><p><strong>Babel</strong> is a type of transpiler Babel is a JavaScript compiler that transforms modern JavaScript code into older versions that are compatible with a wider range of browsers. It allows developers to write code using the latest JavaScript syntax and features while ensuring backward compatibility with older browsers that may not support these features.</p><h4>Role of babel in modern web development</h4><p>The primary role of Babel is to transpile (convert) modern JavaScript code, often written in ES6 (ECMAScript 2015) or later versions, into a version of JavaScript that is supported by the targeted browsers. This process involves parsing the modern JavaScript code and generating equivalent code in older versions that browsers can understand.</p><p><strong>Benefits:</strong></p><ul><li>Compatibility: Babel enables developers to use the latest JavaScript features without worrying about browser compatibility issues.</li><li>Future-proofing: It allows developers to adopt new language features and standards as they emerge, while still ensuring their code runs on older platforms.</li><li>Improved Developer Experience: Developers can write cleaner and more expressive code using modern syntax and features, leading to better maintainability and readability.</li></ul><p><strong>Babel Example:</strong></p><p>Imagine you have some fancy JavaScript code with new features that not all browsers understand. Like this</p><pre>javascript code<br>// Fancy JavaScript code using ES6 arrow function<br>const add = (a, b) =&gt; {<br> return a + b;<br>};</pre><p>But you want your code to work in all browsers, even the old ones that don’t understand these fancy features. So, you use Babel. It’s like a magic translator. You tell Babel, “Hey, can you please translate this fancy code into something simpler that all browsers understand?” Babel translates your code into old-school JavaScript like this.</p><pre>// Translated code that works in all browsers<br>var add = function add(a, b) {<br> return a + b;<br>};</pre><p>Now, you can use this translated code in any browser, and it will work perfectly!</p><p><strong>Webpack </strong>is a powerful static module bundler for JavaScript applications. It takes modules with dependencies and generates static assets representing those modules, which are suitable for deployment on a web server. It’s often used in conjunction with other tools and libraries, such as Babel, to create efficient and optimized web applications.</p><h4><strong>Role of Webpack </strong>in modern web development</h4><p>Webpack’s primary role is to bundle together various assets, such as JavaScript files, CSS files, images, and more, into a single bundle or multiple bundles. This process helps optimize the performance of web applications by reducing the number of HTTP requests needed to load the application and by optimizing the size of assets through techniques like code splitting and minification.</p><p><strong>Benefits:</strong></p><ul><li>Module System: Webpack allows developers to use a modular approach to organize their codebase, which promotes code reuse and maintainability.</li><li>Code Splitting: It enables developers to split their code into smaller chunks, which can be loaded on-demand, improving the initial loading time of the application.</li><li>Asset Optimization: Webpack can optimize assets by minifying JavaScript and CSS files, compressing images, and eliminating dead code, resulting in smaller bundle sizes and faster load times.</li><li>Development Server: It provides a built-in development server with hot module replacement (HMR) capability, allowing developers to see changes in real time without reloading the entire page.</li></ul><h4>The main difference between JavaScript and TypScript</h4><p><strong>JavaScript</strong> is a high-level, multi-paradigm programming language JavaScript is a widely used scripting language in web development. It allows you to create interactive web pages by adding dynamic elements. Primarily used for client-side scripting, JavaScript programs are called scripts. These scripts can be embedded within HTML files (editable in text editors like Notepad or Notepad++) and saved with either a .html or .js extension. The scripts execute when the corresponding HTML page loads. JavaScript can also be used in conjunction with other technologies like XML and APIs. While initially designed for complex applications, JavaScript is perfectly suitable for projects of all sizes, from small-scale tasks to intricate functionalities.</p><p><strong>TypeScript</strong> is an open-source, object-oriented programming language. It builds upon JavaScript, adding features like static typing, classes, and interfaces. These types enhance code readability and maintainability, earning TypeScript the reputation of being a modern approach to JavaScript development. One key concept is type checking for the variable “this,” allowing you to define and enforce data types during compilation. In essence, TypeScript is a superset of JavaScript, sharing most of its syntax with the addition of a few optional features. TypeScript code requires compilation to generate a corresponding JavaScript file.</p><h4>TypeScript development over JavaScript</h4><p>In the very beginning when JavaScript was developed, people were using it just as the client-side programming language. But, later developers got to know that it can also be used as a server-side programming language. As people were using more and more JavaScript, it started getting heavier and more complex. Because of that developers were not able to fulfill the requirement of object-oriented programming language in JavaScript. That sow TypeScript came into the picture to bridge the gap.</p><h4>Why Typescript and JavaScript?</h4><p><strong>JavaScript</strong> is considered a design tool for small application which has a few lines of code i.e. small scripts. You can compile and run JavaScript in any browser javascript also allows cross-compilation.</p><p><strong>TypeScript </strong>is a superset of Javascript as I explained earlier. TypeScript supports JS API Documentation and JS libraries as well. You can convert TypeScript Code into plain JavaScript Code. Typescript is an optionally typed scripting language that means you can write the source code as per the requirement if you want to add typing with Javascript or complete typing, it’s applicable in TypeScript. TypeScript has an object-oriented programming technique and better code structure as compared to JavaScript.If you are using Typescript, then it will also help you to extend the language beyond the standard decorators.</p><h4>Pros of using TypeScript over JavaScript</h4><p>The biggest advantage of using TypeScript is it always highlights errors at compilation time during the time of development, whereas if you use JavaScript, errors get pointed out at runtime. You can run TypeScript on any browser or JavaScript engine.TypeScript includes a feature that is strongly typed or supports static typing. Static typing helps us to check the type correctness at compile time. But, This feature is not available in JavaScript. Typescript can be run on any browser or Javascript Engine.</p><p>Sometimes, It may not be supported in your target browser but the TypeScript compiler can compile the .ts files into ES3, ES4, and ES5 as well. Frameworks like Angular2 also use Typescript as a programming language. Typescript includes a feature that is strongly typed or supports static typing. Static typing helps in checking the type correctness at compile time but this feature is not available in javascript.</p><p>Typescript also has a namespace concept by defining a module. An additional benefit of using Typescript allows great tooling support with IntelliSense which provides active hints as the code is added. In other words, you can say that TypeScript is nothing but JavaScript and some additional features i.e. ES6 features.</p><h4>Features of JavaScript and TypeScript</h4><p><strong>Javascript </strong>is easy to understand and to begin With. You can use Javascript for client side and server side as well. Javascript is a dynamic language i.e. flexible and powerful If you are using Javascript, then you are free to do whatever you want with any object. It has a strong Testing Workflow. Javascript is a cross-platform language. Javascript is not supported in Framework.</p><p>1- JavaScript is an interpreted language. So, the error gets highlighted at runtime itself.</p><p>2- JavaScript directly runs on the browser.</p><p>3- does,t contain the feature of prototyping.</p><p>4- No Annotations are required for JavaScript.It’s a scripting language.</p><p>5- Considers String and Interface as objects and doesn’t support modules.</p><p><strong>TypeScript</strong> can be used anywhere i.e. you can run the source code on any browser, device, or in any OS(operating system). Remember, TypeScript is not specific to any virtual machine. If you are using TypeScript, you can use existing JavaScript code, and incorporate popular JavaScript libraries. And you can also call from other JavaScript code as TypeScript supports JS libraries TypeScript is a superset of Javascript. So, whatever code you write in JavaScript gets converted into TypeScript by changing the extension from .js to .ts. TypeScript Code gets converted into Plain JavaScript Code as Browsers can’t understand the Typescript code. So, if the code is written in TypeScript then the code gets compiled and converted i.e. translated into JavaScript.And by the help of JavaScript code, browsers can read and display the code. This whole process is known as Trans-piled.</p><p>1- The error gets highlighted at compile time.</p><p>2- Can’t run Typescript code on the browser directly.</p><p>3-Typescript consists of a feature of prototyping.</p><p>4-Type language needs to specify type variables, function parameters, and object properties.</p><p>5-Supports classes, inheritance, interfaces, generics.</p><h4>Code example of JavaScript and TypeScript</h4><p>math.js This file contains a simple JavaScript function to add two numbers.</p><pre>javascript code<br>// math.js<br>function add(a, b) {<br> return a + b;<br>}<br>console.log(add(2, 3)); // Output: 5</pre><p>TypeScript Example:</p><p>math.ts This file contains the same function but is written in TypeScript syntax.</p><pre>typescript code<br>// math.ts<br>function add(a: number, b: number): number {<br> return a + b;<br>}<br>console.log(add(2, 3)); // Output: 5</pre><p>In the TypeScript version (math.ts), you’ll notice a few differences:</p><ul><li>Function parameters are annotated with types (: number) to specify the types of a and b.</li><li>The function return type is also a specified number) after the parameter list to specify that the function returns a number.</li><li>The file extension is .ts instead of .js to indicate that it’s a TypeScript file.</li></ul><p>In <strong>conclusion,</strong> compilers, interpreters, transpilers, and polyfills form the backbone of modern web development, enabling developers to write efficient, cross-browser-compatible code. Understanding the differences between these tools and their respective roles is crucial for navigating the complexities of software development. As technologies continue to evolve, staying abreast of new tools and techniques will be paramount for developers seeking to build robust and scalable applications. By mastering these foundational concepts, developers can unlock new possibilities and drive innovation in the dynamic world of programming.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bf49567f80f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Diving into Document Object Model (DOM) Manipulation with JavaScript]]></title>
            <link>https://medium.com/@dev.sheryaramir/diving-into-document-object-model-dom-manipulation-with-javascript-4734e9d98173?source=rss-13ea9a0bdc88------2</link>
            <guid isPermaLink="false">https://medium.com/p/4734e9d98173</guid>
            <category><![CDATA[dom-tree]]></category>
            <category><![CDATA[js-event-handling]]></category>
            <category><![CDATA[dom-manipulation]]></category>
            <category><![CDATA[document-object-model]]></category>
            <dc:creator><![CDATA[Sheryar Amir]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 08:36:54 GMT</pubDate>
            <atom:updated>2024-01-16T08:36:54.048Z</atom:updated>
            <content:encoded><![CDATA[<p>The Document Object Model (DOM) is a crucial aspect of web development, allowing developers to interact with and manipulate the structure, style, and content of HTML documents dynamically. In this article, we will delve into the core concepts of the DOM, exploring its structure, functionality, and how it facilitates the creation of interactive web pages.</p><h3>What is DOM in JavaScript?</h3><p>The Document Object Model (DOM) is a programming interface for HTML It represents the hierarchical structure of HTML or XML documents as a tree of objects, where each object corresponds to elements, attributes, and text within the HTML.</p><p>The DOM provides a standardized way for programs, typically written in languages like JavaScript, to dynamically access, manipulate, and modify the content, structure, and style of HTML. It acts as an interface that allows developers to interact with and modify the elements of an HTML page through scripting.</p><h4>Why did we use DOM?</h4><p>The Document Object Model (DOM) is used for several important purposes in web development:</p><p><strong>Dynamic Content Manipulation:</strong> The DOM allows developers to dynamically manipulate the content, structure, and style of web documents using scripting languages like JavaScript. This enables the creation of interactive and dynamic web pages.</p><p><strong>User Interface (UD Interactivity)</strong>: Developers can use the DOM to respond to user actions such as clicks, inputs, and other events. This interaction is crucial for creating responsive and user-friendly web applications.</p><p><strong>Dynamic Styling:</strong> Developers can use the DOM to dynamically apply or change styles on HTML elements based on certain conditions or user interactions, allowing for dynamic and responsive designs.</p><p>The DOM is essential for dynamic web development because it enables the modification of document content, structure, and style in real-time. By using the DOM, developers can create interactive and responsive web pages, making it a fundamental tool in modern web development.</p><h4>DOM Tree A Hierarchical Representation and Main Node Types</h4><p>The DOM tree, or Document Object Model tree, is a hierarchical representation of the structure of an HTML or XML document. It is created by web browsers when they parse the markup language of a webpage. The tree structure consists of nodes, each representing a part of the document, such as elements, attributes, or text content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XuuvP2Fzjm5-EXTd" /></figure><p>Here’s a brief overview of the key components of the DOM tree:</p><h4><strong>What is DOM Traversing?</strong></h4><p>DOM traversing refers to the process of navigating through the Document Object Model (DOM) tree to access and manipulate elements based on their relationships with other elements. The DOM represents the hierarchical structure of HTML or XML documents, where each HTML element is a node in the tree. Commonly used methods for DOM traversing include.</p><p><strong>Root node</strong>: The root node is the highest in the DOM tree hierarchy, representing the entire HTML or XML document.</p><p><strong>Parent Node</strong>: The parent node is a node that has one or more child nodes directly below it in the hierarchy.</p><p><strong>Child node:</strong> A child node is a node that is directly below another node (its parent) in the hierarchy.</p><p><strong>First Child:</strong> A node&#39;s first child is the node directly below it and is the first among its immediate children.</p><p><strong>Last Child</strong>: The last child of a node is the node that is directly below it and is the last among its immediate children.</p><p><strong>Document Node:</strong> At the top of the tree is the document node, representing the entire HTML or XML document. It serves as the root of the DOM tree.</p><p><strong>Element nod</strong>: Element nodes in the HTML or XML document, such as , “&lt;div”, or “&lt;p&gt;”,&lt;a&gt;, become element nodes in the DOM tree. Element nodes can have children (other nodes) and attributes.</p><p><strong>Attribute Nodes</strong>: Attributes of HTML or XML elements become attribute nodes in the DOM tree. These nodes provide information about the corresponding element.</p><p><strong>Text node</strong>: The textual content within HTML or XML elements becomes text nodes in the DOM tree. For example, the text between,”&lt;p&gt;” and “&lt;/p&gt;”, tags becomes a text node.</p><p><strong>Comment Nodes</strong>: Comments in the document are also represented as nodes in the DOM tree.</p><h3><strong>What is DOM Manipulation?</strong></h3><p>DOM manipulation refers to the process of dynamically modifying the structure, content, or style of a web page using JavaScript. The DOM (Document Object Model) represents the structure of an HTML or XML document as a tree of objects, and JavaScript provides methods and properties to interact with and modify this tree.</p><p>DOM manipulation allows developers to create dynamic and responsive web pages by changing elements, updating content, and responding to user actions.</p><p><strong>Attribute:</strong> an attribute typically refers to a property or characteristic of an HTML element, and it can be accessed and manipulated using the DOM (Document Object Model). HTML elements can have various attributes, such as id, class, src,href, style, etc. These attributes provide additional information about the elements and influence their behavior, appearance, or functionality.</p><p>Here are some common tasks associated with DOM manipulation:</p><h4><strong>Accessing HTML tags by ID names</strong></h4><p>IDs must be unique within an HTML document. You cannot have multiple elements with the same ID.</p><pre>&lt;p id=&quot;toget&quot;&gt; this is a paragraph tag which has a id attribute &lt;/p&gt;</pre><pre>let attr = document.getElementById(&quot;toget&quot;)<br>console.log(attr)</pre><h4><strong>Accessing HTML tags by class names</strong></h4><p>Classes, on the other hand, can be shared among multiple elements. Multiple elements can have the same class. you can select one OR multiple elements of the same class name at a time using various JavaScript methods.</p><pre>&lt;p class=&quot;Myclass&quot;&gt; this is a paragraph tag which has a id attribute &lt;/p&gt;</pre><pre>let attr = document.getElementsByclassName(&quot;Myclass&quot;)<br>console.log(attr)</pre><h4><strong>Accessing HTML tags by tag names</strong></h4><p>you can select one OR multiple elements of the same tag at a time using various JavaScript methods.</p><pre>&lt;p&gt; this is a paragraph tag which has a id attribute &lt;/p&gt;</pre><pre>let attr = document.getElementsBytagName(&quot;p&quot;)<br>console.log(attr)</pre><p>“ <strong>querySe1ector</strong> ” is a method in JavaScript that allows you to select and retrieve the first element in the document that matches a specified CSS selector. It is part of the Document Object Model (DOM) API and provides a powerful way to locate elements using CSS-style selectors.</p><h4>Examples</h4><p><strong>Selecting by Tag Nam</strong>e:</p><pre>&lt;p&gt; this is a paragraph tag which has we can get this by using queryselector &lt;/p&gt;</pre><pre>let fortag = document.querySelector(&quot;p&quot;)<br>//onsole.log(fortag)<br>fortag.style.backgroundColor=&quot;red&quot;</pre><p><strong>Selecting by class Names :</strong></p><pre>&lt;p class= &quot;Myclass&quot;&gt; this is a paragraph which has  class we can get this by using queryselector &lt;/p&gt;</pre><pre>let forclass = document.querySelector(&quot; .Myclass&quot;)<br>//console.log(forclass)<br>forclass.style.backgroundColor=&quot;green&quot;</pre><p><strong>Selecting by class ID Names :</strong></p><pre>&lt;p id =&quot; thisid &quot; &gt; this is a paragraph with id which has we can get this by using queryselector &lt;/p&gt;</pre><pre>let forid = document.querySelector(&quot; # thisid&quot;)<br>//console.log(forid)<br>forid.style.backgroundColor=&quot;blue&quot;</pre><p>“ <strong>querySe1ectorA11&quot;</strong> is a method in JavaScript that allows you to select multiple elements in the DOM using a CSS selector and returns a static Node List representing the list of elements that match the specified selector.</p><p>Examples</p><p><strong>Selecting by Tag Nam</strong>e:</p><pre>let  paragraphs = document.querySelectorAll(&quot;p&quot;);<br>console.log(paragraphs)<br>//in the console all the p tag are return </pre><p><strong>Selecting by class Nam</strong>e:</p><pre>let ElementsWithClass = document.querySelectorAll(&quot;.ExampleClass&quot;);<br>console.log(ElementsWithClass)<br>//in the console all the tags are return which has class name ElementsWithClass</pre><p><strong>Selecting by ID:</strong></p><pre>let ElementsWithID = document.querySelectorAll(&quot;#ExampleID&quot;);<br>console.log(ElementsWithID)<br>//in the console only one tag return which has id name ElementsWithID</pre><p>While you can use “ <strong>querySe1ectorA11</strong>” with an ID selector, it’s less common, as IDs should be unique. If you want just one element, it’s more typical to use getEIementBy1d.</p><h4>DOM Essentials Tags, Inner Text, Append, Before, Remove, get, set</h4><p><strong>To get the Attribute class Name</strong></p><pre>&lt;div class=&quot;theDivClass&quot;&gt;this is a div having the id name theDiv &lt;/div&gt;</pre><pre>let togetClass = document.querySelector(&quot;div&quot;)<br>let Myclass = togetClass.getAttribute(&quot;class&quot;)<br>console.log(Myclass) //theDivClass</pre><p><strong>To get attribute ID Name</strong></p><pre>&lt;div id=&quot;theDiv&quot;&gt;this is a div having the id name theDiv &lt;/div&gt;</pre><pre>let toget = document.querySelector(&quot;div&quot;)<br>let id = toget.getAttribute(&quot;id&quot;)<br>console.log(id)    //theDiv</pre><p><strong>To set a new class Attribute Name</strong></p><pre> &lt;div class=&quot;newone&quot;&gt;this is a div having the id name theDiv &lt;/div&gt;</pre><pre> let togetClass = document.querySelector(&quot;div&quot;)<br> let Myclass = togetClass.setAttribute(&quot;newone&quot; , &quot; mynewclass &quot;)<br> console.log(Myclass) </pre><p><strong>To set a new ID attribute Name</strong></p><pre>&lt;p id=&quot;myid&quot;&gt; Lorem ipsum dolor sit, amet consectetur adipisicing elit. Error, ipsam?&lt;/p&gt;</pre><pre>let togetClass = document.querySelector(&quot;p&quot;)<br>let Myclass = togetClass.setAttribute(&quot;myid&quot; , &quot; mynewid &quot;)<br>console.log(Myclass) <br><br></pre><p><strong>Inner text</strong></p><pre>&lt;p&gt;the inner text key word is used to console the taxt inside any tag &lt;/p&gt;</pre><pre>let para= document.querySelector(&quot;p&quot;)<br>console.log(para.innerText)</pre><p><strong>Creating, Setting Content, and Appending Elements</strong></p><pre>&lt;div class=&quot;main&quot;&gt; <br>    &lt;ul&gt;<br>        &lt;li&gt;home&lt;/li&gt;<br>        &lt;li&gt;contact&lt;/li&gt;<br>        &lt;li&gt;About us&lt;/li&gt;<br>    &lt;/ul&gt;<br>&lt;/div&gt;</pre><pre>let Newbtn=document.createElement(&quot;button&quot;)<br><br>/* Here, a new element is created in the DOM using the<br>document.createE1ement() method. The new button is stored in the variable<br>Newbtn */<br><br>Newbtn.innerText=&quot;click me !&quot;<br>console.log(Newbtn)<br><br>/*The innerText() property is used to set the text content of the newly created button.<br>In this case, the text is set to &quot;click me !&quot;. */<br><br>let toadd=document.querySelector(&quot;div&quot;)<br>toadd.append(Newbtn)<br><br>/*The append method adds the specified element as the last child<br>of the parent element. In this case, the newly created &quot;button&quot; is added as the<br>last child of the selected element. */</pre><p><strong>Prepend a button</strong></p><pre>&lt;div class=&quot;main&quot;&gt;<br>    &lt;ul&gt;<br>        &lt;li&gt;home&lt;/li&gt;<br>        &lt;li&gt;contact&lt;/li&gt;<br>        &lt;li&gt;About us&lt;/li&gt;<br>    &lt;/ul&gt;<br>&lt;/div&gt;</pre><pre>/*The &#39;prepend&#39; method adds a specified element as the first child of another element,<br> allowing dynamic content insertion at the beginning of the DOM structure.*/<br><br>let Newbtn=document.createElement(&quot;button&quot;)<br>Newbtn.innerText=&quot;click me !&quot;<br>console.log(Newbtn)<br><br>let toadd=document.querySelector(&quot;div&quot;)<br>toadd.prepend(Newbtn)</pre><p><strong>Add a button before the “div” tag</strong></p><pre>&lt;div class=&quot;main&quot;&gt;<br>    &lt;ul&gt;<br>        &lt;li&gt;home&lt;/li&gt;<br>        &lt;li&gt;contact&lt;/li&gt;<br>        &lt;li&gt;About us&lt;/li&gt;<br>    &lt;/ul&gt;<br>&lt;/div&gt;</pre><pre>/* <br>The &#39;before&#39; method in JavaScript inserts a specified element before a target element, <br>altering the DOM structure by placing content before the target.*/<br><br>let Newbtn=document.createElement(&quot;button&quot;)<br>Newbtn.innerText=&quot;click me !&quot;<br>console.log(Newbtn)<br><br>let toadd=document.querySelector(&quot;div&quot;)<br>toadd.before(Newbtn)</pre><p><strong>Add a button after the “div” tag</strong></p><pre>&lt;div class=&quot;main&quot;&gt;<br>    &lt;ul&gt;<br>        &lt;li&gt;home&lt;/li&gt;<br>        &lt;li&gt;contact&lt;/li&gt;<br>        &lt;li&gt;About us&lt;/li&gt;<br>    &lt;/ul&gt;<br>&lt;/div&gt;</pre><pre>/*&quot;The &#39;after&#39; method in JavaScript inserts a specified element after a target element,<br> modifying the DOM structure to position content after the target element.&quot; */<br>let Newbtn=document.createElement(&quot;button&quot;)<br>Newbtn.innerText=&quot;click me !&quot;<br>console.log(Newbtn)<br><br>let toadd=document.querySelector(&quot;div&quot;)<br>toadd.after(Newbtn)</pre><p><strong>To delete a tag using the remove method</strong></p><pre> &lt;p&gt;to delete any tag we can used remove key word &lt;/p&gt; </pre><pre>/*The &#39;remove&#39; method in JavaScript deletes a specified element from the DOM, <br>effectively removing it and its content from the document structure */<br>let para= document.querySelector(&quot;p&quot;)<br>para.remove();</pre><h3>What is an Event?</h3><p>Events are things that happen in the system you are programming — the system produces (or “fires”) a signal of some kind when an event occurs, and provides a mechanism by which an action can be automatically taken (that is, some code running) when the event occurs. Events are fired inside the browser window and tend to be attached to a specific item that resides in it. This might be a single element, a set of elements, the HTML document loaded in the current tab, or the entire browser window. Many different types of events can occur.</p><p><strong>For example:</strong></p><p>• The user selects, clicks, or hovers the cursor over a certain element.</p><p>• The user chooses a key on the keyboard.</p><p>• The user resizes or closes the browser window.</p><p>• A web page finishes loading.</p><p>• A form is submitted.</p><p>• A video is played, paused, or ends.</p><p>• An error occurs.</p><h4>What is an event handler?</h4><p>To react to an event, you attach an event handler to it. This is a block of code (usually a JavaScript function that you as a programmer create) that runs when the event fires. When such a block of code is defined to run in response to an event, we say we are registering an event handler.</p><p>Note: Event handlers are sometimes called event listeners — they are pretty much interchangeable for our purposes, although strictly speaking, they work together. The listener listens out for the event happening, and the handler is the code run in response to it happening.</p><p>Web events are not part of the core JavaScript language — they are defined as part of the APIs built into the browser.</p><p>examples</p><p><strong>Multi-Event Click Analysis: Capturing and Logging Click Events on Button</strong></p><pre> &lt;button id=&quot;btn1&quot;&gt;click me once!&lt;/button&gt;</pre><pre>let click=document.querySelector(&quot; #btn1&quot;)<br><br>/*  The addEventListener method typically associates a single event type with a specific<br>HTML element. If you want to handle multiple events for the same element, <br>you would generally use multiple calls to , each specifying a different event<br>type. */<br><br>click.addEventListener(&quot;click&quot;, ()=&gt;{<br>    console.log(&quot;button 1 was click&quot;)<br>})<br><br>click.addEventListener(&quot;click&quot;, ()=&gt;{<br>    console.log(&quot;button 2 was click&quot;)<br>})<br>click.addEventListener(&quot;click&quot;, ()=&gt;{<br>    console.log(&quot;button 3 was click&quot;)<br>})<br>click.addEventListener(&quot;click&quot;, ()=&gt;{<br>    console.log(&quot;button 4 was click&quot;)})</pre><p><strong>Toggle Mode Switch: Dynamically Changing Page Theme on Button Click</strong></p><pre> &lt;button id=&quot;mode&quot;&gt; change mode&lt;/button&gt;</pre><pre>let modeBtn = document.querySelector(&quot;#mode&quot;);<br><br>console.log(modeBtn);<br><br>let currMode = &quot;light&quot;;<br><br>modeBtn.addEventListener(&quot;click&quot;, () =&gt; {<br>    if (currMode === &quot;light&quot;) {<br>        currMode = &quot;dark&quot;;<br>        document.body.style.backgroundColor = &quot;black&quot;;<br>    } else {<br>        currMode = &quot;light&quot;;<br>        document.body.style.backgroundColor = &quot;white&quot;;<br>    }<br><br>    console.log(currMode);<br>});<br></pre><p><strong>Interactive Button Click Logging Event and Incrementing Counter</strong></p><pre>  &lt;button id=&quot;btn&quot;&gt; click Me !&lt;/button&gt;</pre><pre>let btn2 = document.querySelector(&quot;#btn&quot;)<br><br> btn2.onclick =()=&gt;{<br>console.log(&quot;button one was click&quot;)<br>let a=23;<br>a++;<br>console.log(a)<br> }</pre><p><strong>Dynamic Hover Effect Changing Text Color on Mouse Over</strong></p><pre> &lt;div&gt;this is a box&lt;/div&gt;</pre><pre>let box = document.querySelector(&quot;div&quot;)<br><br>box.onmouseover = () =&gt;{<br>    console.log(&quot;you pointer is on the box&quot;)<br>    box.style.color=&quot;red&quot;<br>}</pre><p><strong>Changing Text Color and Background on Mouse Out Event</strong></p><pre>&lt;div&gt;this is a box&lt;/div&gt;</pre><pre>let box = document.querySelector(&quot;div&quot;)<br><br>box.onmouseout = () =&gt;{<br>    console.log(&quot;you pointer is on the box&quot;)<br>    box.style.color=&quot;red&quot;<br>    box.style.backgroundColor=&quot;blue&quot;<br>}</pre><h4>Conclusion</h4><p>The Document Object Model (DOM) plays a pivotal role in web development, enabling dynamic interaction and manipulation of HTML documents. DOM manipulation, achieved through JavaScript, empowers developers to create responsive and interactive web pages by dynamically modifying content, structure, and styles. Understanding the DOM tree structure, traversal methods, and essential concepts like events and event handlers is fundamental to effective web development.</p><p>The ability to dynamically create, set content, and append elements, along with practical examples of DOM manipulation, showcases the versatility and power of JavaScript in enhancing the user experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4734e9d98173" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP vs HTTPS: A Simple Guide to Secure Browsing]]></title>
            <link>https://medium.com/@dev.sheryaramir/http-vs-https-a-simple-guide-to-secure-browsing-a5243ee7e445?source=rss-13ea9a0bdc88------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5243ee7e445</guid>
            <category><![CDATA[http-vs-https]]></category>
            <category><![CDATA[encryption-decryption]]></category>
            <category><![CDATA[symmetric-and-asymmetric]]></category>
            <category><![CDATA[tcp-handshake]]></category>
            <dc:creator><![CDATA[Sheryar Amir]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 17:06:01 GMT</pubDate>
            <atom:updated>2024-01-04T17:06:01.410Z</atom:updated>
            <content:encoded><![CDATA[<p>As we navigate the vast landscape of the internet, two acronyms, HTTP and HTTPS, shape our online experiences. But what do they really mean, and why should we care? In this simple guide, we’ll unravel the world of secure browsing, exploring the key concepts of cryptography, the difference between HTTP and HTTPS, the crucial role of SSL/TLS certificates, and how data flows in the secure HTTPS environment. Join us on a journey to understand the importance of online security and why HTTPS is your superhero in the ever-evolving digital realm.</p><h3>What is Cryptography</h3><p>Cryptography, derived from the Greek words ‘krypto’ (hidden) and ‘graphia’ (writing), isa fundamental element in the realm of network security. At its core, cryptography is the science of secret writing, aiming to safeguard information by concealing its meaning from unauthorized access.</p><h3>Key components of Cryptography</h3><p>Encryption : encryption is the process by which a readable message is converted to an unreadable form to prevent unauthorized parties from reading it. The readable message is called (plaintext) the meaningless message is called (ciphertext).</p><p>Decryption :decryption is the process of converting an encryption message back to its original (readable) format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eGN0cFGZs_Lem7lZ" /></figure><p>Types of Encryption</p><p>Symmetric Encryption is a simple kind of encryption technique that involves only one key to encrypt and decrypt the information .It is also known as secret key cryptography Or private key cryptography.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IkHgvgxYp3lFtZOH" /></figure><p>Asymmetric Encryption: Asymmetric encryption, or public-key cryptography ,is a simple technique using a pair of keys. a public key for encryption and a private key for decryption. This method provides a secure way for communication between parties without the need to share a secret key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fo9Th8KZKy7cTCuj" /></figure><p><strong>What is TCP handshake</strong></p><p>The TCP (Transmission Control Protocol) handshake is a three-step process used to establish a reliable connection between two devices on a network. This handshake is an essential part of the TCP protocol, ensuring that both devices are synchronized before they start exchanging data. Here are the steps involved in the TCP handshake:</p><p>SYN (Synchronize) :The initiating device (client) sends a SYN (Synchronize) packet to the receiving device (server). This packet includes a sequence number, indicating the starting point for the data exchange.</p><p>SYN-ACK(Synchronize-Acknowledge) : Upon receiving the SYN packet, the server responds with a SYN-ACK (Synchronize-Acknowledge) packet. This packet acknowledges the receipt of the SYN packet and includes its own sequence number for synchronization.</p><p>ACK (Acknowledge):The client sends an ACK (Acknowledge) packet back to the server. This packet acknowledges the receipt of the SYN-ACK packet and confirms the establishment of the connection. From this point, data transmission can commencebidirectionally.</p><h3>What are SSL/TLS CERTIFICATES</h3><p><strong>SSL</strong> : stands for Secure Sockets Layer. It is a cryptographic protocol designed to provide secure communication over a computer network, most commonly the internet. Developed by Netscape in the mid-1990s, SSL aimed to establish a secure connection between a client (such as a web browser) and a server (such as a website).</p><p><strong>TLS:</strong> stands for Transport Layer Security. It serves as the successor to the earlier SSL (Secure Sockets Layer) protocol, addressing vulnerabilities found in SSL and introducing improvements in security.</p><p>Any website using TLS or SSL has a lock icon on the left side of https or http because it shows more security.</p><h3>The difference between SSL and TLS ?</h3><ul><li>SSL 3.0 is the final version of SSL, and it is considered insecure due to various vulnerabilities.</li><li>TLS has multiple versions, with each version improving security features. TLS1.3 is the latest and most secure version .</li><li>TLS implementations generally aim for improved performance compared to some older SSL implementations, making TLS more efficient in certain scenarios.</li></ul><h4>What is HTTP and HTTPS ?</h4><p>HTTP stands for hypertext transfer protocol . It operates an application layer of the OSI model designed for communication between web browsers and servers. When you open a web page, your browser uses HTTP to request information from the server, and the server responds by sending the requested data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*UykWsalfAeg0csAL" /></figure><p>HTTPS stands for hypertext transfer protocol secure .HTTPS is a more secure version of HTTP (Hypertext Transfer Protocol), the protocol used for transferring information on the internet. It adds an extra layer of security by encrypting the data exchanged between your web browser and the website you’re visiting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/0*qdQQFBQ-2tceREdH" /></figure><h3>The difference between HTTP &amp; HTTPS</h3><ul><li>HTTP does not include any security certificate to encrypt the data. In contrast, HTTPS includes TLS and SSL digital certificates that help secure communication between client and server.</li><li>HTTP transmits the data in plain text, whereas HTTPS encrypts the data and transmits it in encrypted form.</li><li>HTTP does not need any kind of domain validation. However, HTTPS requires domain validation and even checks legal documents of authentication or ownership.</li><li>HTTP operates at the application layer. HTTPS, on the other side, operates at the transport layer.</li><li>HTTP, by default, uses port 80, whereas HTTPS uses port 443.</li><li>HTTP is comparatively faster than HTTPS because HTTPS consumes more computing power and resources to encrypt the communication channel.</li></ul><p><strong>How does data flow in https?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Cg1YB_1Uk5uf2vAx" /></figure><p>let<strong> </strong>briefly describe the flow chart after the TCP handshake</p><p><strong>Client Hello</strong>: Initiation by Client The TLS handshake begins with the client sending a“ Client Hello ” message to the server. The message includes cryptographic parameters like supported encryption algorithms, supported versions of TLS, random data, and other details.</p><p><strong>Server HelIo :</strong> Upon receiving the “Client Hello,” the server responds with a “Server Hello” message. The “Server Hello” acknowledges the client’s intent, and both parties now agree on the parameters for securing their communication.</p><p><strong>Certificate in Client-Server Connections</strong></p><p>During the TLS handshake, the server presents its digital certificate to the client, containing its public key and signed by a trusted Certificate Authority (CA). The client performs critical certificate checks to ensure the validity and authenticity of the server’s identity. These checks include verifying the CA’s signature, checking the certificate’s expiration date, and ensuring the hostname matches. If any checks fail, the client may terminate the connection to prevent communication with an untrusted server.</p><p>“Client Key Exchange” is a phase during the TLS (Transport Layer Security) handshake where the client sends a unique key to the server. This key is crucial for establishing the shared secret used in encrypting the communication. The server, upon receiving the client’s key, uses it in conjunction with its own private key to derive the shared secret. This shared secret is then employed for encrypting and decrypting subsequent data exchanged between the client and server, ensuring secure communication.</p><p>The “Change Cipher Spec” is a crucial message during the TLS (Transport Layer Security) handshake that signals the transition from non-secure to secure communication. It marks the activation of encryption keys agreed upon during the handshake, ensuring that subsequent data exchanged between the client and server is securely encrypted, enhancing overall communication security. A session key is a temporary encryption key used for securing communication during a specific session between a client and a server. It’s unique to that session and is discarded after use, enhancing security.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5243ee7e445" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>