<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gloria Tejuosho </title>
    <description>The latest articles on DEV Community by Gloria Tejuosho  (@gloriasilver).</description>
    <link>https://dev.to/gloriasilver</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1423222%2F88751fcb-9f2e-457e-9917-147edf3a69b1.jpg</url>
      <title>DEV Community: Gloria Tejuosho </title>
      <link>https://dev.to/gloriasilver</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gloriasilver"/>
    <language>en</language>
    <item>
      <title>How to Pay International Freelancers in 2026</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Thu, 19 Feb 2026 17:21:04 +0000</pubDate>
      <link>https://dev.to/gloriasilver/how-to-pay-international-freelancers-in-2026-2mgn</link>
      <guid>https://dev.to/gloriasilver/how-to-pay-international-freelancers-in-2026-2mgn</guid>
      <description>&lt;p&gt;The world is evolving; new technologies are emerging to improve our daily activities, yet sending money globally still feels like we are in the early 2000s. &lt;/p&gt;

&lt;p&gt;You are either faced with high transfer fees, poor exchange rates, tax compliance headaches, or complex manual processes, especially when you want to process batch transfers. Yet, businesses need to pay their international freelancers or contractors.&lt;/p&gt;

&lt;p&gt;The truth is, there are more convenient and affordable methods to &lt;a href="https://usedots.com/solutions/freelancers/" rel="noopener noreferrer"&gt;send money to freelancers globally&lt;/a&gt;. Unfortunately, only a few people know these options.&lt;/p&gt;

&lt;p&gt;However, this guide will show you a step-by-step process on how to pay international freelancers without expensive fees or complex processes. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to Send Money to Freelancers Globally
&lt;/h2&gt;

&lt;p&gt;The best way to send money to freelancers globally is through the &lt;a href="https://usedots.com/" rel="noopener noreferrer"&gt;Dots platform&lt;/a&gt;. This automated, business-focused payout platform provides a convenient way to send money to a single freelancer or 1000 freelancers at once. You can make this payment directly from a dashboard or make a single API call. &lt;/p&gt;

&lt;p&gt;It also gives you the flexibility to transfer money to over 190 countries, which means you no longer have to worry about geographic restrictions.&lt;/p&gt;

&lt;p&gt;Additionally, recipients can choose to receive the money via their preferred payment method. They can use their digital wallets, such as PayPal, to get paid instantly, or they can receive payment to their local bank account, which typically takes 2 to 5 business days.&lt;/p&gt;

&lt;p&gt;With Dots, you no longer have to worry about tax compliance headaches when you make global payments. The platform handles it for you by collecting and verifying W-9 and W-8 forms from payees, calculating the appropriate withholdings, and generating 1099 forms at year-end.&lt;/p&gt;

&lt;p&gt;For a platform that offers all of these essential perks, you’d expect a high fee. Surprisingly, Dots offers transparent, volume-based pricing, meaning there are no unexpected or hidden charges, and your transaction fee decreases as your payout increases.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use Dots to Transfer Money to International Freelancers
&lt;/h2&gt;

&lt;p&gt;You can send money to freelancers internationally using the Dots Payout Link or the API payout.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Dots Payout Link:
&lt;/h3&gt;

&lt;p&gt;This is the fastest and easiest way to send money to freelancers globally. In fact, you don’t have to collect the payee's bank details before you make the transfer. All you need to do is enter the amount you want to send, optionally enter the recipient's email address or phone number, and create the link via the Dot dashboard or the &lt;code&gt;Create Payout API&lt;/code&gt; endpoint.&lt;/p&gt;

&lt;p&gt;Immediately after your link is created, Dots will send the payout link to the recipient via SMS or email. Then, the recipient claims the link using their preferred payment method to receive funds instantly or within 24 hours.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to Pay International Freelancers With the Dots Payout Link
&lt;/h4&gt;

&lt;p&gt;Follow these steps to instantly pay international freelancers:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; &lt;a href="https://dashboard.dots.dev/login" rel="noopener noreferrer"&gt;Create a Dots account&lt;/a&gt; or log in to your Dots account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Navigate to the Dots dashboard and select the desired App from the sidebar selector.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Select the “Send Payout” tab and click the “Payout Links” button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Enter the amount of money you want to send and optionally enter the recipient’s email address or phone number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ueucis0bfbahf1pka68.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ueucis0bfbahf1pka68.png" alt="An image showing Dots Payouts Interface" width="800" height="520"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Step 5:&lt;/strong&gt; Click the “Create Payout Link” button to proceed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Select your preferred delivery method. I.e., how you want to send the link, either via email, phone, or by copying and pasting the link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6n9nulg8tpwq09p3idt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6n9nulg8tpwq09p3idt.png" alt="An image showing Dots Payout interface for users to select payment delivery options." width="800" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; The recipient receives the link and is redirected to the Dots portal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; The recipient gets onboarded by following the onscreen instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; The recipient enters and verifies his/her phone number. Then select their preferred payment method. Available options include Local bank transfers, wire transfers, PayPal, Venmo, Stripe, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx5uon5at79n9l8dsn4a8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx5uon5at79n9l8dsn4a8.png" alt="An image showing Dots payout interface for users to select preferred payment options." width="800" height="505"&gt;&lt;/a&gt;&lt;br&gt;
The payment is completed instantly or within 24 hours.&lt;br&gt;
You can also use the Payout link to pay international freelancers by integrating the &lt;a href="https://dotsdev.mintlify.app/apireference/payout-links/create-a-payout-link" rel="noopener noreferrer"&gt;Create a Payout Link endpoint&lt;/a&gt; into your system.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Dots API Payout:
&lt;/h2&gt;

&lt;p&gt;If you're after automated payouts and bulk transfers or simply need complete control over the payout process, you should consider integrating the Dots API payout into your system.&lt;/p&gt;

&lt;p&gt;This method allows you to collect the specific information you want from the payee through your user interface and customize the whole payout workflow.&lt;br&gt;
Additionally, you can easily configure webhooks to receive real-time updates when payouts are processed.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Batch Pay International Freelancers Using Dots Batch Payouts API
&lt;/h3&gt;

&lt;p&gt;Follow these steps to batch pay international freelancers with the Dots Payout API:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create a Dots account and &lt;a href="https://dotsdev.mintlify.app/overview/authentication" rel="noopener noreferrer"&gt;get your Dots API credentials&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create a list of users who want to receive the batch payments in your workspace.&lt;br&gt;
Note: Each user must be able to receive payments on the selected rails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Make an API call to the &lt;a href="https://dotsdev.mintlify.app/apireference/payout-batches/create-a-payout-batch" rel="noopener noreferrer"&gt;batch payout endpoint&lt;/a&gt; to create a batch payment&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; &lt;a href="https://dotsdev.mintlify.app/references/webhooks" rel="noopener noreferrer"&gt;Configure the webhooks&lt;/a&gt; to receive live updates as payouts are processed.&lt;/p&gt;

&lt;p&gt;If you want to learn more about the Dots API and how to integrate it into your system, &lt;a href="https://dotsdev.mintlify.app/guides/payout-links" rel="noopener noreferrer"&gt;check out this guide&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Frequently Asked Questions About Paying International Freelancers
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. What is the Best Way to Pay International Freelancers?&lt;/strong&gt;&lt;br&gt;
The best way to pay international freelancers is through an automated payout platform like Dots. It allows you to transfer money to freelancers in over 190 countries, and they receive their payment instantly using their preferred payment method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Can I Pay International Freelancers in Their Local Currency?&lt;/strong&gt;&lt;br&gt;
Yes, you can pay international freelancers directly in their local currency on the Dots platform. It automatically handles currency conversions and selects the fastest, most cost-effective payment rail for sending the money.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. What is the Quickest Way to Transfer Money Internationally?&lt;/strong&gt;&lt;br&gt;
The quickest way to send money globally is through a payment platform like Dots. You can instantly send money to the recipient within 2-5 minutes using a unique payment link. &lt;/p&gt;

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

&lt;p&gt;You don't have to pay high transaction fees or face complex processes before you send money to your international freelancers. &lt;/p&gt;

&lt;p&gt;With the Dots platform, you can transfer money to freelancers in over 190 countries by creating a payment link or by calling a single API endpoint. And the recipients, on the other hand, get to receive their funds instantly, depending on their preferred payment method.&lt;br&gt;
&lt;a href="https://usedots.com/contact-us/" rel="noopener noreferrer"&gt;Book a demo&lt;/a&gt; to learn more about the Dots platform and how you can use it to pay your international freelancers.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Flask vs. Django: Which Framework Should You Choose For Your Project?</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Fri, 03 Oct 2025 20:35:22 +0000</pubDate>
      <link>https://dev.to/gloriasilver/flask-vs-django-which-framework-should-you-choose-for-your-project-3def</link>
      <guid>https://dev.to/gloriasilver/flask-vs-django-which-framework-should-you-choose-for-your-project-3def</guid>
      <description>&lt;p&gt;One minute, you’re getting pumped up to bring your next project idea to life; the next minute, you’re unsure of which web framework to choose between Flask and Django. Things can even get more confusing when you keep reading different viewpoints on why one is better than the other. &lt;/p&gt;

&lt;p&gt;To help you make the right choice, this article will show you reasons why Flask or Django might be the best framework for your project based on their inherent features. You’ll also get to compare the differences between both frameworks, their common use cases, and, most importantly, you’ll know the best framework to choose for your next project once you’re done reading this guide. Let’s get into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reasons Why You Should Consider Flask for Your Next Project
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://flask.palletsprojects.com/en/stable/" rel="noopener noreferrer"&gt;Flask&lt;/a&gt; is a lightweight, micro web framework for Python that allows developers to build and scale web applications quickly. This framework provides the essential tools that developers need to set up and build their project, which gives them the flexibility to seamlessly integrate other libraries and modules based on their project requirements.&lt;br&gt;
Here is why Flask might be a great choice for your next project:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Flexibility:
&lt;/h3&gt;

&lt;p&gt;If you want total flexibility over your application, Flask offers it by default. This framework doesn’t shove built-in features down your throat. Instead, it provides you with only the essential tools you need and gives you the flexibility to choose different libraries or tools that are suitable for your project. &lt;/p&gt;

&lt;p&gt;For example, you have the flexibility to choose a specific database, determine how you want to handle authentication logic, and choose any frontend technologies based on your preference and experience as a developer. There are no strict rules; just go with what works well for you and your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Scalability:
&lt;/h3&gt;

&lt;p&gt;If you want a framework that efficiently handles your application even as your code base grows, then you should consider Flask. This framework has a built-in &lt;a href="https://www.geeksforgeeks.org/python/flask-blueprints/" rel="noopener noreferrer"&gt;Blueprint tool&lt;/a&gt; that allows you to organize related functionalities into a single reusable component. This modularized structure makes it easier to maintain your code base even as it grows.&lt;/p&gt;

&lt;p&gt;For example, you can have an admin interface in a single blueprint to manage users or view analytics and use it across different projects that require an admin area, such as an e-commerce site, a blog, or a learning platform.&lt;/p&gt;

&lt;p&gt;Flask also uses standard specifications such as the &lt;a href="https://builtin.com/data-science/wsgi" rel="noopener noreferrer"&gt;Web Server Gateway Interface (WSGI)&lt;/a&gt; servers to handle multiple concurrent requests. Some notable large applications, such as Netflix, Reddit, Red Hat, and Twilio, are using Flask in their infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Ease of Learning:
&lt;/h3&gt;

&lt;p&gt;If you are looking for a framework that is easy to understand, Flask is a great choice. Flask's approach of providing only the essential tools developers need to set up their application makes it easier to understand its core concepts and build your application quickly.&lt;br&gt;
There are also tons of comprehensive learning resources, including beginner-friendly documentation, online tutorials, and articles, that make the learning and building process smooth for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reasons Why You Should Consider Django for Your Next Project
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.djangoproject.com/" rel="noopener noreferrer"&gt;Django&lt;/a&gt; is a full-stack web framework that provides developers with all the necessary tools and functions they need to develop both the backend and a significant part of the frontend of a web application within a single framework.&lt;/p&gt;

&lt;p&gt;Here is why Django might be a great choice for your next project:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Rapid Development:
&lt;/h3&gt;

&lt;p&gt;If you need a framework that quickly builds your project without delaying you with the overhead of repetitive tasks, then consider Django. It offers a comprehensive set of built-in features that speed up development and eliminate the stress of selecting the right tools.&lt;/p&gt;

&lt;p&gt;For example, the admin interface in Django allows you to create, read, update, and delete data without writing any frontend code. It also has an authentication system that enables you to manage user accounts and an object-relational mapper (ORM) to simplify database operations.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Security:
&lt;/h3&gt;

&lt;p&gt;If your project requires a high level of security, consider using Django. This framework provides extensive built-in security features to protect web applications from vulnerabilities and attacks. &lt;/p&gt;

&lt;p&gt;For example, Django uses a &lt;a href="https://www.blackduck.com/glossary/what-is-csrf.html" rel="noopener noreferrer"&gt;Cross-Site Request Forgery (CSRF)&lt;/a&gt; token to prevent CSRF attacks, i.e., attacks that trick users' browsers into performing unwanted and malicious actions such as changing user passwords or making unauthorized transactions.&lt;/p&gt;

&lt;p&gt;Although developers still need to adhere to core security practices, such as using HTTPS to encrypt communication and regularly conducting security audits to identify and prevent potential vulnerabilities. &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Versatility:
&lt;/h3&gt;

&lt;p&gt;Django is a highly versatile framework that allows you to build a wide range of applications. Whether you want to build an e-commerce platform, a content management system, social sites, or APIs, you can use Django to easily bring them to life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flask vs. Django: What are the Key Differences?
&lt;/h2&gt;

&lt;p&gt;Flask and &lt;a href="https://dtechreative-blog.vercel.app/blog/django-tutorial" rel="noopener noreferrer"&gt;Django&lt;/a&gt; are the best Python frameworks for web development; however, they have their differences. Flask is suitable for smaller applications, while Django is best for complex applications. Flask requires manual configuration, while Django provides built-in tools. Flask is easy to learn, while Django has a steeper learning curve.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;S/N&lt;/th&gt;
&lt;th&gt;Flask&lt;/th&gt;
&lt;th&gt;Django&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;A microframework with limited built-in features&lt;/td&gt;
&lt;td&gt;A full-stack Framework with extensive built-in features&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Suitable for smaller applications such as APIs and Microservice&lt;/td&gt;
&lt;td&gt;Suitable for complex applications such as social sites, e-commerce, and educational platforms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Requires manual configuration of components like authentication&lt;/td&gt;
&lt;td&gt;Facilitates rapid development due to built-in features like an authentication system and admin interfaces.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Highly flexible&lt;/td&gt;
&lt;td&gt;Rigid and has a predefined structure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Easy to learn due to its minimalism and simplicity&lt;/td&gt;
&lt;td&gt;Has a steeper learning curve due to complex features.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Common Use Case of Flask
&lt;/h2&gt;

&lt;p&gt;Flask is commonly used for building RESTful APIs, lightweight applications, and for rapid prototyping.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. RESTful APIs:
&lt;/h3&gt;

&lt;p&gt;Most developers often prefer to use the Flask framework for building &lt;a href="https://aws.amazon.com/what-is-cloud-computing/" rel="noopener noreferrer"&gt;RESTful APIs&lt;/a&gt; due to its flexibility and ease of use. It provides a powerful routing system that enables developers to define URL patterns and map them to specific functions in their applications. It also speeds up the development process by offering extensive libraries for various functionalities like database integration, authentication, request parsing, etc.&lt;/p&gt;

&lt;p&gt;So, if the next project you want to build is a RESTful API, consider using Flask; it is easy to set up and also offers you the flexibility to choose specific tools based on your project needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Lightweight Applications:
&lt;/h3&gt;

&lt;p&gt;Flask is often used to build lightweight applications such as blog apps, news apps, CAPTCHA validation apps, etc., due to its flexibility and simplicity.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Rapid Prototyping:
&lt;/h3&gt;

&lt;p&gt;Flask is commonly used for prototyping, i.e., the process of building a simple version of an app to test its functionalities before building the whole app. Its minimal setup makes it easy for developers to create the prototype of their applications with a few lines of code. In addition,  Flask offers numerous extensions that add various functionalities, such as user authentication, form handling, and database integration, to scale up the prototype to a full application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Use Case of Django
&lt;/h2&gt;

&lt;p&gt;Django, as a full-stack framework with extensive built-in features, is commonly used for building e-commerce applications, social network platforms, and educational applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. E-commerce:
&lt;/h3&gt;

&lt;p&gt;Django is commonly used for building e-commerce applications due to its extensive toolkits that speed up development time. For example, its admin interface enables developers to easily manage product information, track orders, and manage user accounts. Django’s ORM also makes it easy for developers to manage large datasets, including product data, user data, and transactional data.&lt;/p&gt;

&lt;p&gt;So, if you’re planning to build an e-commerce application and want to avoid the complex process of building specific features or functionalities from scratch, consider using Django.  It has all the essential features and tools you need to build and set up your e-commerce application quickly.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Social Network Platforms:
&lt;/h3&gt;

&lt;p&gt;Django is commonly used for building social network platforms based on its inherent scalable architecture. Its architecture supports the integration of robust caching frameworks and efficient load balancing strategies to distribute heavy user traffic and handle large volumes of data and expensive computations on social media apps. Popular social media platforms like Instagram, with over 1 billion active users, use Django in their infrastructure to efficiently manage vast amounts of data.&lt;/p&gt;

&lt;p&gt;So, if the next project you want to bring to life is a social media application, consider using Django to benefit from its scalable architecture and robust authentication and authorization system.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Educational Platforms:
&lt;/h3&gt;

&lt;p&gt;Django’s extensive toolkits also make the framework a great choice for most developers when building educational platforms. Its built-in tools, like the authentication system, make it easy to manage user accounts and course content. &lt;/p&gt;

&lt;p&gt;Django also seamlessly integrates with machine learning libraries, which enables enhanced features such as personalized learning and recommendations for students.&lt;/p&gt;

&lt;p&gt;Whether you're building an online course platform like Udemy or educational resource websites like Khan Academy, you can benefit from Django's extensive capabilities to build your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Choose Flask and Django: Final Verdict
&lt;/h2&gt;

&lt;p&gt;Now that you have examined the features, differences, and common use cases of Flask and Django, which should you choose for your project?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In general, you should consider Flask when building RESTful APIs, small- to medium-sized applications, and when you want full control over your application functionalities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Django, on the other hand, is best for building highly customizable applications that require maximum security and have the potential to scale up in the future.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Frequently Asked Questions About Django and Flask Frameworks
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. What Can Django Do That Flask Cannot?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Django’s comprehensive set of built-in tools allows you to perform specific functionalities that are not inherently available in the Flask framework. For example, the built-in admin interface in Django makes it easy for you to manage database models and data; meanwhile, you have to manually integrate extensions like Flask-Admin when using the Flask framework. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Which is More Secure, Flask or Django?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Django is generally considered more secure than Flask based on its built-in security tools, such as a Cross-Site Request Forgery (CSRF) token to prevent CSRF attacks, Object Relational Mappers (ORMS) to prevent SQL injection, and the use of the &lt;a href="https://docs.djangoproject.com/en/5.2/topics/auth/passwords/#:~:text=By%20default%2C%20Django%20uses%20the,of%20computing%20time%20to%20break." rel="noopener noreferrer"&gt;PBKDF2 algorithm and SHA256&lt;/a&gt;  to hash passwords.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Should I learn Flask or Django in 2025?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The choice ultimately depends on your preference and the type of project you want to build. If you want a framework that is easy to understand and allows you to build small- to medium-sized applications with ease, you should learn Flask. However, if you want a framework that offers extensive built-in features and makes it easy to build complex applications, you should learn  Django.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Can Django Be Used For Full-stack?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, Django can be used for full-stack development. It has robust features and tools that enable developers to handle both the backend and frontend logic of their application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Are Flask Developers Still in High Demand in 2025?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, Flask developers are still in high demand in 2025 for backend roles and API development&lt;/p&gt;

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

&lt;p&gt;Choosing between these two popular web frameworks for Python, Flask and Django, can be tricky. Both frameworks have their unique strengths, weaknesses, and best use cases. &lt;/p&gt;

&lt;p&gt;However, this guide has made the ultimate choice much easier by highlighting the reasons why each framework might be a great choice for your project. It also outlined Flask vs. Django's major differences, as well as the common projects for which each is best suited.&lt;/p&gt;

&lt;p&gt;Now, you can confidently choose the framework that suits your next project needs and bring it to life. Happy building!&lt;/p&gt;

&lt;p&gt;PS: Do you find this post helpful? If yes, feel free to drop your thoughts in the comment section. If otherwise, please share possible tips on how I can better improve the article. Don't worry, I won't take it to heart. :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>django</category>
      <category>backenddevelopment</category>
    </item>
    <item>
      <title>Redefining Identity Management Systems with Blockchain Technology</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Wed, 09 Jul 2025 12:31:54 +0000</pubDate>
      <link>https://dev.to/gloriasilver/redefining-identity-management-systems-with-blockchain-technology-543k</link>
      <guid>https://dev.to/gloriasilver/redefining-identity-management-systems-with-blockchain-technology-543k</guid>
      <description>&lt;p&gt;Data breaches, identity theft, unauthorized access, and many other cyber threats are common issues in traditional identity management systems. One major cause of this challenge is the centralized repository used for storing, managing, and controlling digital identities. This centralized repository may experience downtime due to technical issues or malicious attacks, potentially resulting in data loss or performance bottlenecks.&lt;/p&gt;

&lt;p&gt;There is an urgent need to explore technologies like blockchain to redefine the operations of traditional identity management systems. Blockchain, with its inherent strengths such as decentralization, immutability, and advanced security techniques, can be leveraged in identity management systems to secure user identities and data.&lt;/p&gt;

&lt;p&gt;The advent of blockchain-based identity management, such as Self-Sovereign Identity (SSI) and Decentralized Trust Identity (DTI), also provides a user-controlled way of managing digital identities rather than storing and managing them in a centralized repository.&lt;/p&gt;

&lt;p&gt;How do these technologies work? How does blockchain redefine the operations of identity management systems? All of this will be answered in this article. Read on to learn more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges of Traditional Identity Management Systems
&lt;/h2&gt;

&lt;p&gt;Traditional identity management systems face several challenges, such as single points of failure, lack of user control over data, Compliance and regulatory challenges, and weak authentication processes.&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Single Point of Failure&lt;/strong&gt;: Traditional identity management systems manage and store digital identities in a centralized repository. This approach creates a single point of entry to access data, which often attracts malicious actors to target this point. A successful attack on the system gives them unauthorized access to sensitive data, which can lead to data breaches, financial loss, and reputational damage.&lt;br&gt;
&lt;a href="https://support.okta.com/help/s/article/what-is-okta?language=en_US#:~:text=Okta%20is%20an%20enterprise%2Dgrade%20identity%20management%20service,cloud%20but%20compatible%20with%20many%20on%2Dpremises%20applications.&amp;amp;text=Okta%20features%20include%20Provisioning%2C%20Single%20Sign%2DOn%20(SSO)%2C,flexible%20policies%20for%20organization%20security%20and%20control." rel="noopener noreferrer"&gt;OKTA&lt;/a&gt;, a leading identity management system that provides authentication and authorization services to thousands of organizations, faced a shocking data breach in 2023. The impact of this breach was severe, as malicious actors gained unauthorized access to customer support system information that contains sensitive data such as session tokens, which could be exploited to impersonate users. This breach did not just affect OKTA but also extended to thousands of organizations that rely on it for access control.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Lack of User Control Over Data&lt;/strong&gt;: In traditional identity management systems, user identities and data are managed and controlled by a single entity, such as a corporation or government agency. This approach deprives users of the right to know how their data is stored, shared, and used. It also restricts them from having control over who can access and use their information.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Compliance and Regulatory Challenge&lt;/strong&gt;: Traditional identity management systems may struggle to comply with industry standards or regulations due to the complex and time-consuming process of auditing trails and reporting. The dependence on third-party vendors for authentication also increases compliance risks, which can lead to legal penalties, operational disruption, and reputational damage.&lt;/p&gt;

&lt;p&gt;4.&lt;strong&gt;Weak Authentication Process&lt;/strong&gt;: Traditional identity management has a weak authentication process due to the reliance on passwords, which are susceptible to guessing or phishing. It also supports password reuse across multiple accounts, which can lead to data breaches across all the accounts associated with the password if it gets compromised.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Blockchain Tackles the Challenges in Traditional Identity Management Systems
&lt;/h2&gt;

&lt;p&gt;The blockchain is a distributed digital ledger that stores transactions and data across thousands of nodes that are geographically distributed. It addresses the challenges of traditional identity management in the following ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decentralization&lt;/strong&gt;: The decentralized approach of storing data across thousands of nodes offers a direct solution to the single point of failure challenge in traditional identity management. This removes the need for a central entity to control how digital identities and data are managed, and there is no central point for bad actors to attack and gain entry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Transparency&lt;/strong&gt;: Data stored on the blockchain are transparent and visible to all participants in the network, which can be used to verify the authenticity of data and identities without relying on any central entity. It also enables users to see how their data is stored and managed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Immutability&lt;/strong&gt;: Data stored on the blockchain is immutable, which means that once data is stored, it cannot be manipulated or altered. This provides solutions to cases like unauthorized manipulations by malicious actors and also makes it easier to verify the authenticity of data at any point in its history.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: Blockchain employs several security techniques, such as cryptography, which uses asymmetric keys to secure data. This involves using a private key to encrypt data and a public key to decrypt data to ensure that only authorized users can access the data. This approach ensures maximum security and minimizes cases like unauthorized access, which can help organizations comply with data protection laws like the General Data Protection Regulation (GDPR).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Shift to Blockchain-based Identity Management
&lt;/h2&gt;

&lt;p&gt;Identifying the potential solutions that blockchain technology offers to the challenges of traditional identity management systems, there's a need to embrace a technological shift to blockchain-based identity management systems.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;What is a Blockchain-based Identity System?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A Blockchain-based identity management system uses blockchain technology to create, manage, and store digital identities. This involves storing digital identities across a network of nodes that are geographically distributed; i.e., each node holds a copy of the stored data without relying on any central entity to control its operation. Instead, it uses a consensus mechanism whereby nodes decide the validity of data by checking cryptographic signatures and ensuring all conditions are met to reach an agreement.&lt;/p&gt;

&lt;p&gt;It also leverages several blockchain strengths, such as decentralization, immutability, and cryptography, to tighten the system's security.&lt;/p&gt;

&lt;p&gt;Blockchain-based identity management can be categorized into two.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Self-Sovereign Identity (SSI)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decentralized Trusted Identity (DTI)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Self-sovereign Identity&lt;/strong&gt;: This is a decentralized approach that gives both individuals and organizations maximum control over their digital identities and data. It allows users to store their credentials, such as a national ID or passport, as verifiable credentials in a digital wallet app on their device.&lt;/p&gt;

&lt;p&gt;Then users can use their verifiable credentials to verify their identities when accessing several services, such as online banking, without losing control over their data or giving out all their personal information details.&lt;/p&gt;

&lt;p&gt;The core components of Self-Sovereign Identity are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;i. Verifiable Credentials (VC)&lt;/strong&gt;: These are digital formats of credentials such as a national ID or driver's license issued by trusted entities like the government.&lt;/p&gt;

&lt;p&gt;These credentials are cryptographically secure, tamper-resistant, and follow the standards of the &lt;a href="https://www.w3.org/about/#:~:text=The%20World%20Wide%20Web%20Consortium,together%20to%20develop%20Web%20standards." rel="noopener noreferrer"&gt;world wide web consortium&lt;/a&gt; (W3C).&lt;/p&gt;

&lt;p&gt;With this approach, users can securely share and verify their verifiable credentials with any organization or party without disclosing more information than they need to perform certain actions or access certain services.&lt;/p&gt;

&lt;p&gt;This process typically involves three parties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identity provider&lt;/strong&gt;: These are trusted entities, such as government agencies or universities, that issue a VC to an individual or organization. This VC contains proof or a claim about the individual.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identity holder&lt;/strong&gt;: This refers to the entity that owns the VC. They manage and store it in a digital wallet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identity verifier&lt;/strong&gt;: This is an entity that verifies the authenticity of the submitted VC by reading the records from a Verifiable Data Registry (VDR), i.e., a digital ledger such as a blockchain that securely stores and manages information about VCs. It enables verifiers to validate the authenticity without contacting the issuer.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxk3o0b1sne2ngdb1pt3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxk3o0b1sne2ngdb1pt3.png" alt="How Verifiable credentials work" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ii. &lt;strong&gt;Decentralized Identifiers (DIDS)&lt;/strong&gt;: These are unique and cryptographically verifiable identifiers that identify a user or organization. They're used in the verifiable credentials process.&lt;/p&gt;

&lt;p&gt;Once an issuer issues a VC, they include their public DID, which is stored on a Verifiable Data Registry (VDR), e.g., blockchain. When a verifier wants to verify the authenticity of the VC, they check the DID on the blockchain to check who issued the credentials.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;The ultimate goal of the SSI is to ensure that users have maximum control over their data and digital identities, which aligns with data protection laws and regulations like GDPR&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Decentralized Trusted Identity (DTI)&lt;/strong&gt;: This is also based on the core principle of user-centric data and digital identity management. Its operations are similar to traditional digital identity management due to the involvement of trusted third parties.&lt;/p&gt;

&lt;p&gt;The process typically involves an identity holder registering with a Trusted Third Party(TTP). Then the third-party system verifies the authenticity of the holder's credentials, such as passports or national ID, using an identity proofing system. Upon successful verification, the TTP issues a VC to the holder and records the cryptographic proof of the VC on the blockchain.&lt;/p&gt;

&lt;p&gt;The holder then generates a VC presentation from the VC, i.e., claims extracted from the VC, and presents it to a service provider to access its services. The service provider verifies the authenticity of the VC presentation by comparing it to the cryptographic proof stored on the blockchain.&lt;/p&gt;

&lt;p&gt;Upon successful verification, the service provider grants the holder access to its service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Issue Process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2k2eqrpzq3xmzif2nno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2k2eqrpzq3xmzif2nno.png" alt="Issue process in DTI" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verification Process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0plmx92rqa601jr6nwzt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0plmx92rqa601jr6nwzt.png" alt="Verification process in DTI " width="800" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Life Application of Blockchain-based Identity Management Across Several Sectors
&lt;/h2&gt;

&lt;p&gt;Blockchain-based identity management systems are widely used across several industries to facilitate the management and security of digital identities and data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Healthcare sector&lt;/strong&gt;: Blockchain-based identity management systems are used in the healthcare sector for user authentication and verification before accessing healthcare records. This ensures that only authorized individuals can access health records and prevents cases like data breaches and unauthorized access.&lt;/p&gt;

&lt;p&gt;A notable example of a blockchain-based identity management system is &lt;a href="https://www.media.mit.edu/publications/medrec-blockchain-for-medical-data-access-permission-management-and-trend-analysis/" rel="noopener noreferrer"&gt;MedRec&lt;/a&gt;, a decentralized record management system. It handles the management of electronic health records (EHRS) by providing a secure and verifiable approach to authenticate users and manage their health records. This system uses decentralized identifiers to give users maximum control over their health records and securely share their healthcare status or medical history with authorized authorities. Smart contracts are also used to define access permissions and data management rules to ensure maximum security of health records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Finance sector&lt;/strong&gt;: The financial sector leverages blockchain-based identity management to enhance the security and privacy of customer identities and data. Cryptographic techniques such as digital signatures and hashing are used to verify the authenticity of identities, which reduces cases of unauthorized access and identity theft. The blockchain's immutable nature also ensures that once identity data is recorded, it cannot be altered or deleted&lt;/p&gt;

&lt;p&gt;One of the largest banks in Poland, &lt;a href="https://www.ledgerinsights.com/polish-bank-blockchain-verification/" rel="noopener noreferrer"&gt;PKO Bank Polski&lt;/a&gt; uses blockchain technology like the document authentication approach to authenticate and store bank documents to enhance security and ensure compliance with regulatory laws.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Supply chain management&lt;/strong&gt;: Blockchain-based identity management systems are used in supply chain management to enhance the security of users’ data and the authenticity of products. This involves using decentralized identifiers to enable users to control and manage their digital identities, allowing them to easily verify their identities and minimize risks such as data breaches or identity theft.&lt;/p&gt;

&lt;p&gt;Product authenticity can also be easily verified by assigning a digital identity to each product to ensure transparency and traceability. An example is &lt;a href="https://everledger.io/" rel="noopener noreferrer"&gt;Ever Ledger&lt;/a&gt;, a company that uses blockchain technology to create unique digital identities for luxury assets such as diamonds, which helps ensure that they can only be accessed by authorized stakeholders. It also uses blockchain immutability and transparency to ensure asset records can be tracked and verified in real-time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Blockchain-based Identity Management Systems
&lt;/h2&gt;

&lt;p&gt;The blockchain-based identity management system offers several advantages, such as enhanced security, transparency, user control, minimizing cyber threats, and compliance with regulations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Enhanced security&lt;/strong&gt;: Several blockchain security techniques, such as the public-private key pair, enhance security by enabling users to use their private key to encrypt data and their corresponding public key to verify its authenticity, rather than relying on weak authentication processes like passwords. Blockchain immutability also ensures that once identity data is stored on the blockchain, it cannot be manipulated or altered, which reduces threats like unauthorized manipulations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Transparency&lt;/strong&gt;: Data stored on the blockchain is publicly visible to the network participants, which enables users to see how their digital identities and data are stored, managed, and used. This also fosters integrity and trust because changes made are visible to all participants, giving no room for shady manipulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. User control&lt;/strong&gt;: Self-sovereign identities give users maximum control over their data, allowing them to selectively disclose their information to necessary parties. Users can also verify their identity by providing only the relevant information to access some services, rather than sharing all their sensitive data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Minimizes cyber threats&lt;/strong&gt;: The decentralized approach of managing and storing users' identities across nodes minimizes cyber threats like data breaches and prevents unauthorized access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Enhance compliance regulations&lt;/strong&gt;: Blockchain-based identity management uses smart contracts to automate compliance and predefined rules rather than the time-consuming manual verification process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges of Blockchain-based Identity Management System
&lt;/h2&gt;

&lt;p&gt;Blockchain-based identity management systems offer several techniques to secure digital identities and data. However, it's not without its trade-offs. Challenges such as scalability, interoperability, and user adoption are problems associated with these systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Scalability&lt;/strong&gt;: Scalability issues are inherent problems on blockchain platforms due to their low transaction processing speed, which often leads to delays in identity verification, especially when the system has a large user base. The use of computationally expensive consensus mechanisms such as Proof of Work (POW) to validate transactions on some blockchains, like Bitcoin, also makes the system less scalable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Interoperability&lt;/strong&gt;: Different blockchain-based identity management systems use different protocols, consensus mechanisms, and regulatory frameworks, which hinder the transfer and exchange of digital identities and data across blockchain platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. User Adoption and Experience&lt;/strong&gt;: Managing cryptographic keys, interacting with smart contracts, and understanding blockchain concepts can be complex for non-technical users, which can limit their adoption.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Addressing the challenges that face traditional identity management is crucial, as they pose serious cyber threats to digital identities. In this article, we have explored the various ways in which blockchain features such as decentralization, immutability, and transparency can reduce these risks.&lt;/p&gt;

&lt;p&gt;Embracing a technological shift towards blockchain-based identity management systems like SSI and DTI also provides a user-controlled way to manage data, enabling users to have maximum control over their digital identities, which can minimize risks associated with unauthorized access, identity theft, and enhance compliance with data protection laws and regulations.&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blaize.tech/blog/blockchain-digital-identity/#:~:text=Blockchain%20digital%20identities%20enhance%20supply,traceability%20throughout%20the%20supply%20chain" rel="noopener noreferrer"&gt;Introduction to Digital Identity Blockchain&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.researchgate.net/publication/322383187_A_First_Look_at_Identity_Management_Schemes_on_the_Blockchain#pf6" rel="noopener noreferrer"&gt;A First Look at Identity Management Schemes on the Blockchain&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.avatier.com/blog/navigating-compliance-and-identity-management-challenge/" rel="noopener noreferrer"&gt;Navigating Compliance Headaches: Overcoming the Identity Management Challenge&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dl.acm.org/doi/fullHtml/10.1145/3486622.3493917" rel="noopener noreferrer"&gt;Blockchain-Based Self-Sovereign Identity: Survey, Requirements, Use-Cases, and Comparative Study&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>identitymanagementsystem</category>
    </item>
    <item>
      <title>Introduction to XBanking as a Dividend token platform</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Wed, 06 Nov 2024 18:32:44 +0000</pubDate>
      <link>https://dev.to/gloriasilver/introduction-to-xbanking-as-a-dividend-token-platform-4hmf</link>
      <guid>https://dev.to/gloriasilver/introduction-to-xbanking-as-a-dividend-token-platform-4hmf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Imagine a groundbreaking innovation that allows you to be a shareholder in a blockchain-based company.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;That is, you can invest in the company, earn a crypto reward, take part in the decision-making of the company, and many more benefits.&lt;br&gt;
This is where &lt;strong&gt;XBanking&lt;/strong&gt;, a leading platform in the world of DeFi dividend tokens comes into play. &lt;/p&gt;

&lt;p&gt;What's the DeFi dividend token, What is XBanking? What benefits does XBanking offer? &lt;br&gt;
All of these questions will be answered in this article. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is DeFi dividend token?
&lt;/h2&gt;

&lt;p&gt;DeFi dividend token is a decentralized innovation that simulates traditional dividends. In the traditional market, you can be a shareholder in a company by investing money and then you get a percentage of the company's earnings in return. For example, you can be a shareholder in Google company by simply investing your money and then you get a dividend (reward) in return. &lt;br&gt;
This is similar to the concept of the DeFi dividend token. &lt;/p&gt;

&lt;p&gt;DeFi dividend token offers crypto dividends from a company's earnings to its token holders in the form of regular holders. That's, if you were to be a token holder in a DeFi dividend platform like XBanking, you get a percentage of their token in return.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hint: Token holders are like shareholders in the traditional market.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is XBanking as a dividend token?
&lt;/h2&gt;

&lt;p&gt;XBanking (XB) is a leading platform in the world of DeFi dividend tokens, that pays a percentage of XBanking platform profit to token holders. &lt;/p&gt;

&lt;h3&gt;
  
  
  Who are XB token holders?
&lt;/h3&gt;

&lt;p&gt;These are users who hold the Xb token(the native cryptocurrency of XBanking)&lt;br&gt;
In a bid to compensate its holders, XB offers a range of rewards like higher profits, empowering them with the voting right to take part in the platform, NFTs, bonus dividends, and more. &lt;/p&gt;

&lt;h2&gt;
  
  
  Significant features of XBanking
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Defi Dividends&lt;/strong&gt;: XB offers a percentage of the platform earnings to its token holders based on the ecosystem activities. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced security&lt;/strong&gt;: XBanking maintains the security of its ecosystem by undergoing regular audits by reputable firms like Certik. This security helps to protect user's assets and to build a reliable platform that everyone can trust. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Governance Participation&lt;/strong&gt;: XB empowers token holders to participate in the decision-making of the company through Decentralized Autonomous Organization (DAO) management. This feature gives users a sense of ownership in the platform. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reward and Incentives&lt;/strong&gt;: XB offers its users several rewards by providing them with free tokens, Non-Fungible Tokens (NFTs), Airdrops, and bonuses. This reward system encourages users to actively participate in the XB platform &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trust and Transparency&lt;/strong&gt;: As a DeFi platform, XB leverages the transparency and trust that DeFi offers. This feature enables all transactions and dividends to be visible to its holders, which helps users to have full access to track their earnings and helps to build a solid trust with investors. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The XBanking platform is a promising innovation in the world of DeFi dividend tokens as it continues to evolve and implement strategies to serve its users and maintain its position as the leading DeFi dividend token. &lt;/p&gt;

&lt;p&gt;Visit our website:&lt;/p&gt;

&lt;p&gt;Website: &lt;a href="https://xbanking.org" rel="noopener noreferrer"&gt;https://xbanking.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;X: &lt;a href="https://x.com/xbanking_org" rel="noopener noreferrer"&gt;https://x.com/xbanking_org&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Telegram: &lt;a href="https://t.me/xbanking" rel="noopener noreferrer"&gt;https://t.me/xbanking&lt;/a&gt;&lt;/p&gt;

</description>
      <category>besttoken</category>
      <category>bloc</category>
      <category>xbtoken</category>
    </item>
    <item>
      <title>Roll-ups: The Ultimate Solution To Blockchain Scalability Issue</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Thu, 31 Oct 2024 19:08:53 +0000</pubDate>
      <link>https://dev.to/gloriasilver/roll-ups-the-ultimate-solution-to-blockchain-scalability-issue-1f99</link>
      <guid>https://dev.to/gloriasilver/roll-ups-the-ultimate-solution-to-blockchain-scalability-issue-1f99</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;'What use are the key features of blockchain if it can’t efficiently handle a large number of users at a time?' This question concerns the scalability issue&lt;/em&gt; the blockchain ecosystem is currently facing.&lt;/p&gt;

&lt;p&gt;Blockchain technology possesses several significant features that have led to its wide adoption across several industries. One of its key features is decentralization, which ensures the blockchain is not controlled by a single entity and provides a trustless system.&lt;/p&gt;

&lt;p&gt;Blockchain technology also employs several security techniques, such as digital signatures, hash functions, and public keys, to tighten the network's security. However, as the number of users in the network increases, it struggles to efficiently process their transactions, thereby leading to high fees&lt;/p&gt;

&lt;p&gt;This is a result of the limited block space in the blockchain since they can only process a limited number of transactions. If the number of transactions to be processed exceeds the network capacity, the network will become congested. This often leads to slow transaction processing speed, slower confirmation time, and high gas prices.&lt;/p&gt;

&lt;p&gt;Resolving this scalability issue is a difficult task because blockchain networks cannot offer decentralization, security, and scalability simultaneously. This is termed the ‘&lt;strong&gt;blockchain trilemma&lt;/strong&gt;’.&lt;/p&gt;

&lt;p&gt;The blockchain trilemma refers to the concept that describes the limitations of the blockchain system to possess decentralization, security, and scalability simultaneously. &lt;br&gt;
It states that a blockchain network can only possess two of these three critical features. That is, if a blockchain network is decentralized and secured, then its scalability will be sacrificed.&lt;/p&gt;

&lt;p&gt;Sacrificing any of these features is not a feasible option; otherwise, the blockchain will not attain its optimality. This challenge raises the need for a solution to efficiently tackle this problem.&lt;br&gt;
This is where the power of Roll-ups comes into play. &lt;/p&gt;

&lt;p&gt;What are roll-ups? How do roll-ups efficiently scale the blockchain networks without sacrificing decentralization or security?&lt;/p&gt;

&lt;p&gt;This article will provide answers to these questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer-1 and layer-2 Network
&lt;/h2&gt;

&lt;p&gt;Before explaining what Roll-ups are, let's understand the concept of layer-1 and layer-2 networks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer-1 Network
&lt;/h3&gt;

&lt;p&gt;Layer-1 is the foundational layer of the blockchain architecture that executes and validates transactions without the support of additional layers. However, it has a limited number of blocks, which makes it unable to efficiently process large transactions at a time.&lt;/p&gt;

&lt;p&gt;An example of a layer-1 blockchain is Ethereum. It can only process about fifteen transactions per second, which means the network gets congested when there is a high demand. Other layer-1 blockchains are Bitcoin, Solana, Avalanche, etc.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: Layer-1 can also be referred to as the Base layer and they will be used interchangeably in this article.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer-2 Network
&lt;/h3&gt;

&lt;p&gt;Layer-2 is a secondary protocol built on top of Layer-1. It is a solution designed to increase the functionalities and efficiency of the layer-1 blockchain. Think of the layer-2 network as a flyover built on top of a highway(layer-1). The function of a flyover is to reduce congestion on the highway and facilitate faster vehicle movement by providing another route on the highway. &lt;/p&gt;

&lt;p&gt;This is similar to the way layer-2 works. It is built on top of layer-1 to reduce network congestion by offloading transactions from the on-chain network and processing them off-chain while still inheriting the underlying security of the layer-1 blockchain. Roll-ups are one of the most popular types of layer-2 scaling solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Roll-ups?
&lt;/h2&gt;

&lt;p&gt;Roll-ups are layer 2 scaling solutions that help increase the scalability of the blockchain network without sacrificing decentralization and security. They achieve this by offloading transactions from the layer-1 blockchain and processing them off-chain. &lt;/p&gt;

&lt;p&gt;Once a user submits a transaction, an operator (entity responsible for processing transactions) picks it up and bundles multiple transactions into a single batch. Then the batch transaction is submitted to the layer-1 network.&lt;/p&gt;

&lt;p&gt;The process of offloading transactions from layer-1 and processing them off-chain reduces congestion and increases the transaction processing speed. Transaction costs are also reduced because the fee is now shared among all users in the transaction batch.&lt;/p&gt;

&lt;p&gt;This makes Roll-up a viable solution to the blockchain scalability problem, as it increases transaction processing speed and reduces transaction costs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ms9hq3j6sebmoj7068l.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ms9hq3j6sebmoj7068l.jpeg" alt="Roll-ups" width="383" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Roll-ups.
&lt;/h2&gt;

&lt;p&gt;There are two common types of Roll-ups. The difference between them lies in how the roll-up checks the validity of the transactions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Zero-knowledge Roll-up:&lt;/strong&gt; This is a type of roll-up that uses zero-knowledge proof (ZKP) to verify transactions processed off-chain. ZKP, also known as validity proof, is a mechanism whereby a party known as a prover proves the validity of a transaction to another party, called a verifier, without revealing all the information.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A simple analogy of how this proving system works is a scenario where you want to prove that you meet a certain age requirement without revealing your actual date of birth, place of birth, or any other sensitive information. You can achieve this by using your birth certificate to generate proof, such as a statement that displays ‘I am over 18 years old’.&lt;br&gt;
Then you can tender this proof while the verifier verifies it without knowing any other information about you. &lt;/p&gt;

&lt;p&gt;This is similar to the way batched transactions are verified. For each batch transaction processed off-chain, a proof is generated and submitted to layer-1. The prover uses this proof to prove that the transactions processed off-chain were done correctly, while the verifier verifies the validity of the transaction without knowing its entire information. After the verifier confirms that it's valid, the batch transaction is added to layer-1.&lt;/p&gt;

&lt;p&gt;The process of using validity proof to verify transactions ensures that the security of the network is not compromised. &lt;br&gt;
Therefore, Zk Roll-up provides a solution to the blockchain scalability issue without compromising the security of the network.&lt;br&gt;
Examples of Zk roll-ups are &lt;a href="https://www.alchemy.com/overviews/what-is-zksync-era" rel="noopener noreferrer"&gt;Zksync Era&lt;/a&gt;, &lt;a href="https://polygon.technology/blog/layer-2-demystified-how-polygon-scales-ethereum" rel="noopener noreferrer"&gt;Polygon&lt;/a&gt;, and &lt;a href="https://www.starknet.io/" rel="noopener noreferrer"&gt;Starkware&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Optimistic Roll-up:&lt;/strong&gt; In optimistic roll-up, the process of verifying transactions processed off-chain is different from Zk Roll-up. Optimistic Roll-up assumes that the off-chain transactions are valid by default. They operate on the principle of  ‘innocent until proven guilty'.&lt;br&gt;
This means that they don't publish proof of validity for off-chain transactions.&lt;/p&gt;

&lt;p&gt;Once a user submits a transaction, a sequencer (an entity responsible for ordering and processing transactions) picks it up and processes it off-chain.The processed transactions are then submitted with the new layer-2 state (the state of the roll-up after the submitted transactions were executed) back to layer-1.&lt;/p&gt;

&lt;p&gt;To ensure the validity of the submitted transaction, the verifier nodes compare the expected state of the transactions with the proposed one submitted by the sequencer. If there's a difference between them, that signifies a potentially fraudulent transaction. A time frame known as the challenge period occurs when the verifier challenges the sequencer that submits the transactions by using fraud proof.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: It is only when they detect potentially fraudulent activities that they initiate fraud proof.&lt;/p&gt;

&lt;p&gt;The fraud proof will execute the transaction processed off-chain on layer 1 to ensure it is not manipulated. If the result of the fraud proof is different from the one submitted by the sequencer, the initial bond of the sequencer (the amount staked as a pledge to act honestly)  will be slashed and the transaction will be erased and recomputed.&lt;/p&gt;

&lt;p&gt;This process helps to ensure that scalability is increased without compromising the security and decentralization of the blockchain network.&lt;br&gt;
Examples of blockchains that use optimistic roll-ups are &lt;a href="https://cointelegraph.com/explained/what-is-optimism-ethereums-layer-2-scaling-solution-explained" rel="noopener noreferrer"&gt;Optimism&lt;/a&gt;, &lt;a href="https://cointelegraph.com/learn/what-is-base-coinbase-l2-network" rel="noopener noreferrer"&gt;Base&lt;/a&gt;, and &lt;a href="https://cointelegraph.com/learn/arbitrum-the-next-generation-layer-2-for-ethereum" rel="noopener noreferrer"&gt;Arbitrum&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Roll-ups
&lt;/h2&gt;

&lt;p&gt;Roll-ups offer several benefits, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Increased scalability:&lt;/strong&gt; Roll-up significantly increases the scalability of the blockchain network by offloading transactions from layer-1 and processing them off-chain. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduced Cost&lt;/strong&gt;: Roll-ups reduce transaction costs by allowing users to split the cost of processing batch transactions instead of paying for each transaction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Increased user experience:&lt;/strong&gt; Roll-ups increase user experience by processing transactions faster and enabling faster confirmation time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintaining security and decentralization:&lt;/strong&gt; Roll-ups still inherit the robust security of its underlying layer-1 network by transferring the responsibility of transaction ordering to Layer-1.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of Roll-ups
&lt;/h2&gt;

&lt;p&gt;Despite the numerous advantages Roll-ups offer, it's not without its drawbacks.&lt;br&gt;
Some of the drawbacks of roll-ups include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fraud vulnerability&lt;/strong&gt;: Roll-ups can be vulnerable to fraudulent activities in cases where there are issues in the roll-up itself or when there are vulnerabilities in the underlying smart contract that the roll-up is interacting with.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security Tradeoffs&lt;/strong&gt;: The two main types of Roll-ups have their trade-offs. Zk Roll-up offers enhanced security, but it uses a complex cryptographic computation. On the other hand, Optimistic Roll-ups are simple and flexible, but they require a seven-day challenge period to verify transactions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implementation Complexity&lt;/strong&gt;: Implementing Roll-ups requires complex processes such as processing transactions off-chain, generating cryptographic proof (ZK Roll-up), and using fraud detection mechanisms (Optimistic Roll-up).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Roll-ups offer an ultimate solution to the blockchain scalability problem without sacrificing either decentralization or security. Its ability to process transactions off-chain helps to reduce congestion on the base layer, increase the transaction processing speed, and reduce cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://coinmarketcap.com/academy/glossary/layer-1-blockchain" rel="noopener noreferrer"&gt;https://coinmarketcap.com/academy/glossary/layer-1-blockchain&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cyfrin.io/blog/what-are-blockchain-rollups-a-full-guide-to-zk-and-optimistic-rollups" rel="noopener noreferrer"&gt;https://www.cyfrin.io/blog/what-are-blockchain-rollups-a-full-guide-to-zk-and-optimistic-rollups&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cyfrin.io/blog/what-is-a-zk-rollup" rel="noopener noreferrer"&gt;https://www.cyfrin.io/blog/what-is-a-zk-rollup&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.alchemy.com/overviews/optimistic-rollups" rel="noopener noreferrer"&gt;https://www.alchemy.com/overviews/optimistic-rollups&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>articles</category>
    </item>
    <item>
      <title>Sybil Attack in the Blockchain Network</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Mon, 14 Oct 2024 04:57:50 +0000</pubDate>
      <link>https://dev.to/gloriasilver/sybil-attack-in-the-blockchain-network-317h</link>
      <guid>https://dev.to/gloriasilver/sybil-attack-in-the-blockchain-network-317h</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Blockchain ecosystem has continued to grow in prominence and is becoming widely adopted across several industries. This growth is attributable to its functional characteristics like decentralization, immutability, and cryptographic techniques that create a highly secured system. &lt;/p&gt;

&lt;p&gt;The blockchain's decentralized nature removes the need for a central control entity to oversee its operation. &lt;/p&gt;

&lt;p&gt;Additionally, data stored on the blockchain network is immutable which means it cannot be altered or manipulated.&lt;br&gt;
It uses cryptographic techniques like digital signature, hash function, and public keys to maintain the security of the network.&lt;/p&gt;

&lt;p&gt;However, despite the efforts to secure blockchain networks, malicious actors still attempt to launch cyber-attacks and disrupt the integrity of the system. One such attack is the &lt;strong&gt;Sybil attack.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What Is Sybil Attack? How does this attack weaken the security of the blockchain network and what security measures can be taken to counter it?&lt;/p&gt;

&lt;p&gt;This article will provide answers to these questions, read on to learn more.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Sybil attack?
&lt;/h2&gt;

&lt;p&gt;A Sybil attack is a malicious act in which attackers create multiple fake nodes often known as &lt;strong&gt;Sybil nodes&lt;/strong&gt; to attack a system with the intent of gaining the majority of influence in the network and making it work for their selfish interest.&lt;/p&gt;

&lt;p&gt;The name ‘Sybil'  was inspired by a book in 1973, named ‘&lt;a href="https://en.m.wikipedia.org/wiki/Sybil_(Schreiber_book)" rel="noopener noreferrer"&gt;Sybil&lt;/a&gt;' where a character in the book suffered from a dissociative identity disorder. A disorder that is characterized by having multiple personalities.&lt;/p&gt;

&lt;p&gt;In the blockchain network, a sybil attack involves a single entity creating multiple fake nodes to hijack the authority of the blockchain network, corrupt its reputation, and exploit the system to carry out illegal activities.&lt;/p&gt;

&lt;p&gt;Attackers can use these multiple fake nodes to gain a large control of the system. This control gives them the ability to alter the decision-making in the system, manipulate transactions, and undermine the consensus mechanism.&lt;/p&gt;

&lt;p&gt;Consensus mechanism is the method used to reach an agreement on the state of the blockchain. This ensures that the majority of the nodes in the network are holding the same copy of the transactions to validate that the transaction is legitimate.  &lt;/p&gt;

&lt;p&gt;Attackers can manipulate this consensus mechanism by amassing enough sybil nodes to outvote the authentic nodes. This enables them to approve or reject transactions, block authentic nodes, and create confusion among them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can a single attacker control multiple fake nodes in a decentralized network?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Although a decentralized network cannot be controlled by a central entity, attackers can control these multiple sybil nodes because they're a single entity disguised as multiple independent networks. &lt;/p&gt;

&lt;p&gt;Once a sybil attack is launched into a decentralized network, the attackers can single-handedly control the multiple sybil nodes to perform fraudulent activities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of blockchain sybil attack
&lt;/h2&gt;

&lt;p&gt;Sybil nodes can attack the blockchain network in two major ways.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Direct Sybil Attack:&lt;/strong&gt; This is a form of attack where sybil nodes are disguised as real nodes to interact with the original nodes in the system. &lt;br&gt;
The original nodes being unable to identify those fake nodes interact with them. Through this interaction, attackers can gain influence and exploit the original nodes to carry out their fraudulent activities. &lt;br&gt;
For instance, attackers can manipulate the original nodes to approve malicious transactions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60550ic3mjruuxmztp79.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60550ic3mjruuxmztp79.png" alt="Direct Sybil attack" width="800" height="529"&gt;&lt;/a&gt;&lt;br&gt;
   &lt;em&gt;An illustration that explains how direct sybil attack works&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Source: cyfrin updraft&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Indirect Sybil Attack:&lt;/strong&gt; This attack involves an indirect method of using an intermediary or proxy node to interact with the original nodes. &lt;br&gt;
The sybil nodes first exploit the intermediary nodes and then use the exploited intermediary node to launch an attack on the original nodes.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgj1b9saajy04qewpp9ji.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgj1b9saajy04qewpp9ji.png" alt="Indirect Sybil attack" width="800" height="591"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;An illustration that explains how indirect sybil attack works.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;source: cyfrin updraft.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This indirect attack is difficult to detect because there's no direct interaction between the sybil nodes and original nodes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consequence of the sybil attack on the blockchain network
&lt;/h2&gt;

&lt;p&gt;Successful sybil attacks in a blockchain network can cause catastrophic effects on the blockchain system such as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Restriction of authorized users in the network&lt;/strong&gt;: In a sybil attack, attackers have the majority of control over the network which can restrict the original nodes from participating in the voting system or validating transactions. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Undermining consensus mechanism&lt;/strong&gt;: Attackers can deteriorate the integrity of the consensus mechanism by using the sybil nodes to take the majority of the votes in the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Security breaches&lt;/strong&gt;: Attackers can use the sybil nodes to extract sensitive information like personal information and financial transactions from the original nodes which is against the blockchain principle of prioritizing security and anonymity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sybil Resistance Mechanism
&lt;/h2&gt;

&lt;p&gt;A Sybil resistance mechanism is a technique used to prevent hackers from creating multiple fake nodes that can affect a peer-to-peer network or blockchain system.&lt;/p&gt;

&lt;p&gt;This system is implemented to ensure that attackers cannot easily gain the majority of influence in the network by enforcing users to first prove their honesty before they can join the network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of sybil resistance mechanisms
&lt;/h2&gt;

&lt;p&gt;The types of sybil resistance are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Proof of work (POW)&lt;/strong&gt;: This mechanism enforces miners(users) to solve computationally intensive tasks to prove their honesty. &lt;br&gt;
This task involves miners expending their computational resources to find a valid hash.&lt;br&gt;
A hash is a unique fingerprint for data.&lt;/p&gt;

&lt;p&gt;Miners go through a continuous trial and error process of changing the &lt;a href="https://www.investopedia.com/terms/n/nonce.asp" rel="noopener noreferrer"&gt;nonce value&lt;/a&gt; in the block header. When this nonce value is combined with the block transaction and hashed with a hash function like SHA256 used in Bitcoin, it must meet the targeted hash value set for the task they are to perform in the network.&lt;/p&gt;

&lt;p&gt;It is only after they get the valid hash and other participants in the network verify it before they are added to the block.&lt;/p&gt;

&lt;p&gt;This process means that malicious actors trying to launch multiple fake nodes must go through the difficult process of finding answers to the required complex problems for each node that they want to add to the network.&lt;/p&gt;

&lt;p&gt;This approach seems unachievable and a waste of computational resources because they need to amass enough nodes (more than 50%) before they can control the network. &lt;/p&gt;

&lt;p&gt;Therefore, the proof of work mechanism prevents a sybil attack by enforcing miners to prove their honesty by solving computationally intensive tasks before they can add a node to the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Proof of Stake(POS)&lt;/strong&gt;: This is another mechanism used to prevent Sybil attacks where users(validators) are required to stake their cryptocurrencies as collateral before they can participate in the network. &lt;/p&gt;

&lt;p&gt;Unlike POW where miners compete against each other to be the first to get a valid hash before they can propose a block, validators are pseudo-randomly picked, i.e., Validators are selected randomly and those who stake high have a higher chance of being selected.&lt;/p&gt;

&lt;p&gt;Once they're selected, other validators in the network validate it to ensure It's legitimate.&lt;/p&gt;

&lt;p&gt;Validators that successfully propose a valid block earn a reward and if a validator tries to compromise the network by acting dishonestly, a substantial amount of their staked assets is slashed and they'll be removed from the network.&lt;/p&gt;

&lt;p&gt;This process makes it difficult for malicious actors to launch a sybil attack because they have to stake an asset upfront for each node they want to run.&lt;br&gt;
Sponsoring more than 50% of these nodes to gain majority control in the network is way too expensive and they are at risk of losing everything once the attack fails.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Notes
&lt;/h2&gt;

&lt;p&gt;Sybil's attack poses a serious threat to the blockchain, however, the Sybil resistance mechanism such as proof of work and proof of stake can counter this attack by making it extremely difficult for malicious actors to create multiple sybil nodes.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>cryptocurrency</category>
    </item>
    <item>
      <title>How to schedule tasks using JavaScript Timers and Intervals</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Mon, 01 Jul 2024 12:10:39 +0000</pubDate>
      <link>https://dev.to/gloriasilver/how-to-schedule-tasks-using-javascript-timers-and-intervals-4385</link>
      <guid>https://dev.to/gloriasilver/how-to-schedule-tasks-using-javascript-timers-and-intervals-4385</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript is a dynamic language that allows web developers to add interactive features to web applications. Among its built-in functions are &lt;code&gt;setTimeout&lt;/code&gt; and &lt;code&gt;setInterval&lt;/code&gt;, used for scheduling tasks and managing timing within applications.&lt;/p&gt;

&lt;p&gt;In this article, we will examine how the &lt;code&gt;setTimeout&lt;/code&gt; and &lt;code&gt;setInterval&lt;/code&gt; functions work and gain hands-on experience through practical examples. &lt;br&gt;
 Before proceeding, it's essential to have a basic understanding of JavaScript. You can refer to this &lt;a href="https://www.w3schools.com/js/" rel="noopener noreferrer"&gt;article&lt;/a&gt;  if you need to.&lt;/p&gt;
&lt;h2&gt;
  
  
  setInterval and setTimeout
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;setInterval&lt;/code&gt; and &lt;code&gt;setTimeout&lt;/code&gt; are both essential for managing timing in JavaScript applications. However, these functions serve different purposes and have distinct use cases. &lt;br&gt;
Let's get into each function's specific use cases and understand when to appropriately use them in our applications.&lt;/p&gt;
&lt;h3&gt;
  
  
  setInterval
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;setInterval&lt;/code&gt; is a method that repeatedly executes a code at intervals defined by a specified time(In milliseconds). &lt;br&gt;
It ensures that the code runs each time the specified interval elapses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;setInterval syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;param1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;param2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt;: The code to be executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delay&lt;/strong&gt;: The specified interval for the code to execute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;param1, param2&lt;/strong&gt;: Optional parameters to be passed to the function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: Using the setInterval function to display "Hello" after every second.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greetings&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setInterval&lt;/code&gt; takes two parameters: An anonymous function that logs "Hello" to the console, and a specified time interval of 1000 milliseconds which equals 1 second. &lt;br&gt;
&lt;code&gt;greetings&lt;/code&gt;: A variable that holds the interval Id returned by the setInterval function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;: Create a count down timer with hours, minutes, and seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Set up the &lt;code&gt;html&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt; &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Change Style&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"countdown"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;app.js&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 

  &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Include JavaScript code to achieve the countdown timer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timeRemaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;hours&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Display the initial time&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;countdown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hours&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; hours, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; minutes, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; seconds`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Update the countdown every second&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;countdownTimer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Convert the time to seconds&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;totalSeconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hours&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minutes&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Decrement the time by 1 second&lt;/span&gt;
  &lt;span class="nx"&gt;totalSeconds&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Convert the time back to hours, minutes, and seconds&lt;/span&gt;
  &lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hours&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalSeconds&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;totalSeconds&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;totalSeconds&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Display the updated time&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;countdown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hours&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; hours, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; minutes, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;timeRemaining&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; seconds`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Check if the countdown is complete&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalSeconds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Countdown complete!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;timeRemaining&lt;/code&gt; object that holds the remaining number of times in the countdown.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Display the initial time by accessing &lt;code&gt;timeRemaining&lt;/code&gt; element and updating the &lt;code&gt;Dom&lt;/code&gt; with the Id "countdown".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;setInterval&lt;/code&gt; creates an anonymous function and a specified time interval that runs every second.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Inside the anonymous function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;totalSeconds&lt;/code&gt; variable converts the remaining time into seconds.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;totalSeconds --&lt;/code&gt;: Decreases the time by 1 second.&lt;/li&gt;
&lt;li&gt;Convert the time back to hours, minutes, and seconds.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;Math.floor&lt;/code&gt; method to round down each value to the nearest whole number.&lt;/li&gt;
&lt;li&gt;Update the &lt;code&gt;Dom&lt;/code&gt; element with the updated time.&lt;/li&gt;
&lt;li&gt;Use the conditional "If" statement to check if the countdown Is complete and a pop alert message if not so.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This example demonstrates the use of &lt;code&gt;setInterval&lt;/code&gt; to create a countdown timer that updates every second, with hours, minutes, and seconds displayed. &lt;/p&gt;

&lt;h3&gt;
  
  
  clearInterval
&lt;/h3&gt;

&lt;p&gt;This is a method that clears the function that was previously declared in the &lt;code&gt;setInterval&lt;/code&gt;. It clears the function in the &lt;code&gt;setInterval&lt;/code&gt; when it's no longer needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;clearInterval Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;clearInterval &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;intervalId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;clearInterval&lt;/strong&gt;: The function used to cancel repeating intervals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;intervalId&lt;/strong&gt;: The identifier of the interval to be cleared.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: Using the &lt;code&gt;clearInterval&lt;/code&gt; to remove the function in the &lt;code&gt;setInterval&lt;/code&gt; once the total seconds is less than or equal to zero.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalSeconds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearInterval &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;countdownTimer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Countdown complete!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, &lt;br&gt;
&lt;code&gt;setInterval&lt;/code&gt;function created a countdown timer and  &lt;code&gt;clearInterval&lt;/code&gt; removed the function once the total seconds reached zero.&lt;/p&gt;
&lt;h3&gt;
  
  
  Importance of using clearInterval
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It keeps code clean and efficient making it easier to maintain and debug.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It prevents memory leaks by stopping background interval execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It clears unnecessary code execution once it is no longer needed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  setTimeout
&lt;/h3&gt;

&lt;p&gt;Set timeout is a method that executes a task after a specified delayed time (in milliseconds). It executes the task only when the specified time elapses.&lt;br&gt;
 It calls the function once unlike the setInterval function that calls a function repeatedly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;setTimeout syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;milliseconds&lt;/span&gt;&lt;span class="p"&gt;...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;function&lt;/strong&gt;: The code to be executed after a specified delay.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Milliseconds&lt;/strong&gt;: The time delay before the function is executed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: Use setTimeout to display "Welcome to my page" after 2 seconds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome to my page&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: &lt;br&gt;
&lt;code&gt;setTimeout&lt;/code&gt; takes two parameters: An anonymous function that displays an alert with the message "Welcome to my page" and a delay time of 2000 milliseconds(or 2 seconds) before the function is executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;: Use &lt;code&gt;setTimeout&lt;/code&gt; to display a list of messages after 2 seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Set the html elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Display Messages&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"style.css"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Display Messages&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"startBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; Start message sequence&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;app.js&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Include JavaScript code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Second message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Third message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fourth message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;startBtn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;startBtn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;messageFunction&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

 &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;messageIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messageFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;All messages displayed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;startBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nf"&gt;messageFunction &lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;strong&gt;messages&lt;/strong&gt;: An array that contains the list of messages to be displayed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;startBtn&lt;/strong&gt;: A variable that targets the start button.&lt;br&gt;
message: A variable that targets the messages to be displayed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;messageIndex&lt;/strong&gt;: A variable that holds the index of the messages to be displayed. Its initial value is set to 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;messageFunction()&lt;/strong&gt;: A function that checks for two conditions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the messageIndex is less than the length of the messages to be displayed, then, it displays each messages after 2 seconds using the setTimeout method&lt;/li&gt;
&lt;li&gt;If this condition is not met, then it displays "All messages have been displayed".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Add an eventListener that invokes the messageFunction once the 'start button' is clicked.&lt;br&gt;
This example demonstrates the use of setTimeout to display a list of messages every 2 seconds.&lt;/p&gt;
&lt;h3&gt;
  
  
  clearTimeout
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;clearTimeout&lt;/code&gt; is a method that clears a timer that was previously created in the &lt;code&gt;setTimeout&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;clearTimeout syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="nf"&gt;clearTimeout &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setTimeoutId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;clearTimeout&lt;/code&gt;: The function used to cancel a timeout.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setTimeoutId&lt;/code&gt;: The identifier of the timer to be canceled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: Use the clearTimeout to cancel the message sequence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create a button to stop the message sequence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt; Display Messages&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"style.css"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Display Messages&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"startBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; Start message sequence&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"stopBtn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; Stop message sequence &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;app.js&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Add clearTimeout to the 'stop' button&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Second message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Third message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fourth message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;startBtn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;startBtn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stopBtn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stopBtn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;messageFunction&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

 &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;messageIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messageFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;All messages displayed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;startBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;messageIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nf"&gt;messageFunction &lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;stopBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEvenListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nf"&gt;clearTimeout &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Message sequence stopped!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;strong&gt;stopBtn&lt;/strong&gt;: A variable that targets the 'stop button' element.&lt;br&gt;
 An &lt;code&gt;eventListener&lt;/code&gt; is added to the  'stop button ' which uses the &lt;code&gt;clearTimeout&lt;/code&gt; method to cancel the timeout.&lt;br&gt;
This makes the message sequence stop once the stop button is clicked.&lt;/p&gt;

&lt;h3&gt;
  
  
  Importance of clearTimeout
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;It clears the &lt;code&gt;setTimeout&lt;/code&gt; method when it's no longer needed.&lt;/li&gt;
&lt;li&gt;It prevents memory leaks by avoiding background execution.&lt;/li&gt;
&lt;li&gt;It makes code clean and easy to debug.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Best Practices
&lt;/h3&gt;

&lt;p&gt;There are best practices to follow when using the &lt;code&gt;setInterval&lt;/code&gt; or the &lt;code&gt;setTimeout&lt;/code&gt; function to prevent errors and ensure clean, efficient code. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;setInterval&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Always use the &lt;code&gt;clearInterval&lt;/code&gt; to stop intervals from running in the background.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store the &lt;code&gt;setInterval&lt;/code&gt; function inside a variable to easily access it inside  the &lt;code&gt;clearSetTimeout&lt;/code&gt; function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the &lt;code&gt;try&lt;/code&gt;-&lt;code&gt;catch&lt;/code&gt;to handle and debug errors. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;setTimeout&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Always clear the &lt;code&gt;setTimeout&lt;/code&gt; when it is no longer needed to prevent memory leaks. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set a reasonable amount of time when using&lt;code&gt;setTimeout&lt;/code&gt;.&lt;br&gt;
Avoid too short a time which can cause execution to occur suddenly and too long a time which can affect user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store the &lt;code&gt;setTimeout&lt;/code&gt; function in a variable to easily access it in the &lt;code&gt;clearTimeout&lt;/code&gt; function. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Knowing when to use the setInterval and setTimeout functions is crucial, and we have discussed the types of functions they perform, when to use them, and best practices to follow. You should be able to use them effectively in your code.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Utilizing the useEffect Hook for Handling Side Effects</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Sun, 30 Jun 2024 20:14:43 +0000</pubDate>
      <link>https://dev.to/gloriasilver/utilizing-the-useeffect-hook-for-handling-side-effects-njb</link>
      <guid>https://dev.to/gloriasilver/utilizing-the-useeffect-hook-for-handling-side-effects-njb</guid>
      <description>&lt;p&gt;The &lt;code&gt;useEffect&lt;/code&gt; hook is a crucial tool in React for managing side effects, i.e., actions that occur outside the scope of a component. &lt;br&gt;
Examples of side effects include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetching data&lt;/li&gt;
&lt;li&gt;Event listeners&lt;/li&gt;
&lt;li&gt;Setting and clearing timers&lt;/li&gt;
&lt;li&gt;Updating the DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By leveraging &lt;code&gt;useEffect&lt;/code&gt;, we can keep our applications organized, efficient, and easy to maintain. &lt;/p&gt;

&lt;p&gt;In this article, we'll discuss the best practices for using the &lt;code&gt;useEffect&lt;/code&gt; hook in our projects.&lt;/p&gt;

&lt;p&gt;Before we proceed, you need to have a basic understanding of React fundamentals, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React components&lt;/li&gt;
&lt;li&gt;Basics of react hooks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you need a refresher, check out this article on &lt;a href="https://www.freecodecamp.org/news/learn-react-basics-in-10-minutes/" rel="noopener noreferrer"&gt;FreeCodeCamp.&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  useEffect Syntax
&lt;/h3&gt;

&lt;p&gt;The useEffect takes two parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A function that handles the side effect logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An optional dependency array that determines whether the effect should re-render.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nf"&gt;useEffect &lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="p"&gt;},[])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;To solidify your knowledge, we will use useEffect to handle a side effect by fetching a list of users data from GitHub.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Import &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useState&lt;/code&gt; Hook at the top level of your component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; will create a state variable that stores the users’ data.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useEffect&lt;/code&gt; will handle the side effects when fetching the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Create a component and declare the &lt;code&gt;useState&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UseComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setUsers&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState &lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;

    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;   &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Create a &lt;code&gt;url&lt;/code&gt; variable that holds the link to the API&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.github.com/users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Create a &lt;code&gt;getUser&lt;/code&gt; function to fetch the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="nf"&gt;setUsers &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We used the &lt;code&gt;async await&lt;/code&gt; method to fetch the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;response&lt;/strong&gt;: This fetches the data from the url variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;users&lt;/strong&gt;: Gets the response variable and changes it to a json.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;setUsers&lt;/strong&gt;: This function updates the user's state from an empty array to hold the fetched data in the &lt;code&gt;user&lt;/code&gt;'s variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Invoke the &lt;code&gt;getData&lt;/code&gt; function inside the &lt;code&gt;useEffect&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;useEffect &lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;)}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt;: Add the dependency array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;useEffect &lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;),[]}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dependency array ensures that the function passed i.e &lt;code&gt;getUsers&lt;/code&gt; only runs once after the initial render. &lt;br&gt;
This helps to avoid unnecessary API calls on subsequent renders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7&lt;/strong&gt;: Use the &lt;code&gt;map&lt;/code&gt; method to display the new data stores in the&lt;code&gt;user&lt;/code&gt; state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UseComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setUsers&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState &lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;GitHub&lt;/span&gt;  &lt;span class="nx"&gt;Users&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;githubUsers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;login&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;avatar_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;html_url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;githubUsers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wrapper&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
           &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;avatar_url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;login&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
         &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;login&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h4&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;         &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;html_url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="nx"&gt;Profile&lt;/span&gt; 
         &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;         &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;         &lt;span class="p"&gt;})&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;   &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;map&lt;/code&gt; method, we destructured each data in the &lt;code&gt;user&lt;/code&gt; state i.e &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;login&lt;/code&gt;, &lt;code&gt;avatar_url&lt;/code&gt;, &lt;code&gt;html_url&lt;/code&gt; properties &lt;br&gt;
and they are assigned to each html tag. &lt;/p&gt;

&lt;p&gt;This makes the user data fetched from the API display.&lt;/p&gt;

&lt;p&gt;Notice how we used the &lt;code&gt;useEffect&lt;/code&gt; hook to handle the side effect of fetching data from an API, and implemented a dependency array to ensure that the API call only executes after the initial render.&lt;br&gt;
This optimises the performance and also prevents redundant data fetching.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best practices when using useEffect
&lt;/h3&gt;

&lt;p&gt;UseEffect is a crucial tool in React applications, and best practices should be followed when using it to avoid slowing down the application's performance and unnecessary re-renders. &lt;br&gt;
These include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Always use the dependency array as the second argument in useEffect.&lt;br&gt;
The dependency array ensures that the effects only execute when the specified dependencies change, preventing unnecessary re-renders.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the clean-up function&lt;/strong&gt;: The cleanup function helps remove unnecessary side effects, preventing memory leaks.&lt;br&gt;
E.g. Using the cleanup function to clean up a timer like setTimeout or setInterval prevents them from running unnecessarily and avoids memory leaks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use multiple useEffect for unrelated logics&lt;/strong&gt;: When dealing with multiple unrelated logics, it's essential to use separate useEffect hooks for each logic, making your code more readable, manageable, and easier to understand. E.g&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use useEffect for side effects only&lt;/strong&gt;: Avoiding uses such as handling events, rendering components, or initializing state. Reserve &lt;code&gt;useEffect&lt;/code&gt; for tasks like fetching data, setting timers, or updating the DOM, which has a tangible impact on the component's behaviour. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we examined the useEffect hook, its purpose, and when to use it. &lt;br&gt;
Additionally, we discussed best practices for using the useEffect hook to ensure optimised code in our React application.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to use the useState Hook in React</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Wed, 22 May 2024 06:43:03 +0000</pubDate>
      <link>https://dev.to/gloriasilver/how-to-use-the-usestate-hook-in-react-2dga</link>
      <guid>https://dev.to/gloriasilver/how-to-use-the-usestate-hook-in-react-2dga</guid>
      <description>&lt;h1&gt;
  
  
  How to use the useState() Hook In React
&lt;/h1&gt;

&lt;p&gt;A React hook is a special function that allows you to add states and other features to functional components without writing a class.&lt;br&gt;
It was introduced in the 16.8 version of React.&lt;/p&gt;

&lt;p&gt;Hooks provides a concise way to handle states in React application.&lt;/p&gt;

&lt;p&gt;Examples of these hooks include useState, useEffect, useReducer, useContent, etc.&lt;/p&gt;

&lt;p&gt;In this article, we will be looking at one of the most widely used hooks, useState.&lt;/p&gt;

&lt;p&gt;But before proceeding with this article, you need to have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A code editor  (preferably visual studio code)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Vite React app running on your IDE&lt;br&gt;
You can check this &lt;a href="https://www.npmjs.com/package/create-vite" rel="noopener noreferrer"&gt;article&lt;/a&gt; to proceed with Vite installation In case you don't have it installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic knowledge of HTML, CSS, and JavaScript to understand the concepts behind what we will be explaining in this article.&lt;br&gt;
. Beginner knowledge of React.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  What is useState?
&lt;/h2&gt;

&lt;p&gt;useState is a react hook that allows you to add states to functional components. The state contains data or information about the component. It can be an array, object, string, number, or boolean.&lt;/p&gt;

&lt;p&gt;When you call the useState, you pass in the initial value for your state. Then React returns an array with two elements. i.e. The current State value and a function to update it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useState syntax&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const [state, setState] = useState(initialValue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have the 'state' variable and a function 'setState' to update our current state. Then, the 'initialValue' takes the value of the current state.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to use the useState hook
&lt;/h3&gt;

&lt;p&gt;-&amp;gt; Import useState at the top level of your components as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0800wu8eutl1vuk8gy0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0800wu8eutl1vuk8gy0.png" alt="how to import useState Hook" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; Invoke it inside a React component: After you have imported useState, then, you proceed to invoke it inside your function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi83orrfwwmvqp8gy6pqm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi83orrfwwmvqp8gy6pqm.png" alt="how to invoke our state" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the function 'myExample', &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first value, 'age' is our current state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;'setAge' is the function used to update our state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;useState () sets our current state, Age to 10.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, we can now make use of our state inside the function component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpynhltq7koce4mw7zuqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpynhltq7koce4mw7zuqz.png" alt="A code that describes how we used our useState hook" width="800" height="590"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After declaring our state, then, we proceed to make use of it inside our component.&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;outputs&lt;/strong&gt; “My current age is 10.”&lt;/p&gt;

&lt;h3&gt;
  
  
  How to update state value
&lt;/h3&gt;

&lt;p&gt;We can update the state by using the updater function (setState) with the new state. Once the component re-renders, then, the state takes the value of the updated state.&lt;/p&gt;

&lt;p&gt;This is illustrated in the example below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssk7jb15907y9dut04j3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssk7jb15907y9dut04j3.png" alt="how to update our state" width="800" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above, to update our state, we created a function, “updateAge" and then we used our second element setAge to update our current state.&lt;/p&gt;

&lt;p&gt;Then, we invoked our function inside the button elements by using the onClick event. Anytime we click on the button, our components re-render and update our state by adding 1 to the current age.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiple States
&lt;/h3&gt;

&lt;p&gt;In React, we are not limited to having just one state in our components; we can add multiple states.&lt;br&gt;
 Additionally, states can hold different kinds of data types, as shown in the example below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fls9c39edkdn3muujmufd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fls9c39edkdn3muujmufd.png" alt="Multiple States" width="800" height="928"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our example, we have three different states.&lt;/p&gt;

&lt;p&gt;-The first state 'name' takes the &lt;strong&gt;string&lt;/strong&gt; data type.&lt;br&gt;
-The second state 'age' takes the &lt;strong&gt;number&lt;/strong&gt; data type.&lt;br&gt;
-The third state 'hobbies' takes the &lt;strong&gt;array&lt;/strong&gt; data type.&lt;br&gt;
Then, we nicely display these states inside our component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conditional Rendering
&lt;/h3&gt;

&lt;p&gt;React allows us to render components based on specified conditions. Just like JavaScript conditionals, where we use if else statements or Ternary operators to set conditions.&lt;/p&gt;

&lt;p&gt;In React we can also use these methods and then the short circuit evaluation to specify conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using if statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The if statement in React works just like it does in JavaScript.&lt;br&gt;
In the example below, we use an if statement to determine age eligibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp1lni2z9s77uz4nf8o2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp1lni2z9s77uz4nf8o2t.png" alt="using 'if' statement to specify condition" width="800" height="610"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using short circuit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Why do we need the Short Circuit operator?&lt;/p&gt;

&lt;p&gt;The reason why we need to use the Short circuit operator and Ternary operators is that we cannot use the ‘If’ statement in all cases because the 'If' statement doesn't return a value and remember, in React, you must always return an expression.&lt;/p&gt;

&lt;p&gt;If you run the example below, it will return an error because the ‘If’ statement doesn't return a value, which is the reason why we have to go for the Short circuit operator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftd8xdrswqay21wtm3iv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftd8xdrswqay21wtm3iv.png" alt="Inappropriate use of If statement" width="800" height="798"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The short-circuit operator makes use of the Logical OR operator and the AND operator&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the OR operator&lt;/strong&gt;: The OR operator checks for the condition specified, if the first condition is falsy, it will return the second value. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Explanation&lt;/em&gt;&lt;br&gt;
 In the example below, the first condition was false because it was set to an empty string then it returned the second value of &lt;br&gt;
“John Doe.”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bt4bg0ynmcnj61tihyl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bt4bg0ynmcnj61tihyl.png" alt="using OR operator" width="800" height="791"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Essentially, if you change the first condition to true, it will return the first value. “Hello World"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwqqd80sknz9bh4karoi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwqqd80sknz9bh4karoi.png" alt="OR operator" width="800" height="582"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the And operator &amp;amp;&amp;amp;&lt;/strong&gt; : The AND operator works a little bit differently.&lt;/p&gt;

&lt;p&gt;if the first condition is truthy, it returns the second value, and if it's falsy, it returns the first value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmc6ztx8z29chnd6zii2k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmc6ztx8z29chnd6zii2k.png" alt="using AND operator" width="800" height="582"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code Explanation:In the first example above, the first condition was true, then it returned the second value of “John Doe."&lt;/p&gt;

&lt;p&gt;-&amp;gt; And operator II example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fod9ml52pm2y8hotxx4yu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fod9ml52pm2y8hotxx4yu.png" alt="AND operator" width="800" height="690"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we change the first condition to false, it returns the first value which is an empty string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the Ternary operator&lt;/strong&gt;: The Ternary operator uses a question mark and a colon. If the first condition is met, it returns the first value, else it returns the second value.&lt;/p&gt;

&lt;p&gt;In the example below, we hide the name “John Doe" by using the Ternary operator to specify a condition.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lmby43dbk37ptykul0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lmby43dbk37ptykul0q.png" alt="Ternary operator" width="800" height="801"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We start by setting the name state to false, then we use the setName inline function to toggle the state between true and false by using the (!) symbol. &lt;br&gt;
&lt;em&gt;Hint&lt;/em&gt;: The exclamation mark (!) Is a 'NOT' operator that returns the opposite boolean value of the expression that follows it.&lt;/p&gt;

&lt;p&gt;Notice how we added a little bit of inline styling and the onClick handler to handle the click event once the ‘toggle’ button is clicked.&lt;/p&gt;

&lt;p&gt;Once the condition Is true, it shows the name “John Doe" else, it hides the name.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we learned about useState Hook in react. We examined how to use the useState, how to update our state, and how to conditionally render our components.&lt;br&gt;
I hope you enjoyed the tutorial.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>coding</category>
    </item>
    <item>
      <title>Introduction To Document Object Model(DOM)</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Wed, 08 May 2024 17:55:27 +0000</pubDate>
      <link>https://dev.to/gloriasilver/document-object-model-oha</link>
      <guid>https://dev.to/gloriasilver/document-object-model-oha</guid>
      <description>&lt;p&gt;The &lt;strong&gt;DOM&lt;/strong&gt; is an essential concept in web development that enables dynamic access and modification of a web page's content. &lt;/p&gt;

&lt;p&gt;In this article, we will discuss what DOM entails, why it's necessary, and how to use it to manipulate the content of an HTML document. However, before we proceed, it's important for you to have a solid understanding of HTML, CSS, and JavaScript fundamentals. If you're not familiar with these concepts or need a refresher, you can check out the &lt;a href="https://www.w3schools.com" rel="noopener noreferrer"&gt;w3Schools&lt;/a&gt; article.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Document Object Model?
&lt;/h2&gt;

&lt;p&gt;The Document Object Model, often known as ‘DOM’ for short, is the hierarchical representation of document elements in documents such as HTML or XML.&lt;/p&gt;

&lt;p&gt;The elements of the documents are represented in a tree order of objects, where each branch of the tree ends in a node. These nodes simply represent parts of the documents, such as elements, attributes, or text strings.&lt;br&gt;
 However, the order in which the nodes are arranged is basically based on the order of creation. The document itself is a node, and its children are referred to as child nodes. Each child node also has its respective children, as explained in the illustration below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8lh3ybk4u5xso56tz7jn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8lh3ybk4u5xso56tz7jn.png" alt="The HTML DOM Tree Of Objects" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why is the Dom Necessary?&lt;/p&gt;

&lt;p&gt;The DOM allows us to use interactive programming languages like JavaScript to dynamically access the content of a document and control how it will be displayed in a web browser. It facilitates various types of actions, such as changing the text content, attributes, tags, and styles of the document. &lt;br&gt;
 Additionally, it handles events in a web browser, such as click events, mouseovers, and keyboard inputs.&lt;/p&gt;
&lt;h3&gt;
  
  
  How do we access the document using the DOM?
&lt;/h3&gt;

&lt;p&gt;Before we can access the content of a document, we need to first target the element we want to access, which leads us to &lt;strong&gt;JavaScript DOM Selectors.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript DOM Selectors&lt;/strong&gt; are used to select HTML elements or nodes within a document using JavaScript.&lt;/p&gt;
&lt;h4&gt;
  
  
  Types of DOM Selectors:
&lt;/h4&gt;

&lt;p&gt;-&amp;gt;&lt;strong&gt;getElementById() method&lt;/strong&gt;:This method is used to select an element by providing its Id tag.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With getElementById, we were able to target the element that has an id of “myId"&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;getElementsByClassName() method&lt;/strong&gt;: This method is used to select all the elements that have a specified class name.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myClass&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With getElementsByClassName, we can target the element that has a class name of “myClass." &lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;getElementsByTagName() method&lt;/strong&gt;: This targets the elements by specifying their tag name.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myTag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByTagName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With getElementsByTagName, we can target all the elements with the tag name “li".&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;querySelector() method&lt;/strong&gt;: This method returns the first element that matches the specified selector.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;       &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;. example&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt; &lt;strong&gt;querySelectorAll () method&lt;/strong&gt;: This method returns all the elements that match the specified selector, unlike the querySelector.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.example);

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  How to manipulate/change the content of an HTML document
&lt;/h4&gt;

&lt;p&gt;After we have targeted the element we want to change using the selectors we discussed earlier, we can now manipulate the content of the HTML using the following methods&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;innerHTML property&lt;/strong&gt;: This allows us to read and update the content of HTML elements.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;change&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt; &lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello People&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;We target the element with an Id of “myId" and then we use the innerHTML property to change the content to “Hello People".&lt;/p&gt;

&lt;p&gt;The code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Change Text&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;Id=&lt;/span&gt;&lt;span class="s"&gt;"myId"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; Hello World&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt; 
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;change&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;myId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt; &lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello People&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsgockhjkyp6eq4qme8x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsgockhjkyp6eq4qme8x.jpg" alt="Code output" width="719" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how we changed the div element from "Hello World” to " Hello People.”&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Style property&lt;/strong&gt;: This property allows you to change the style of an HTML element.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const change = document.getElementsByClassName("page")[0].style.color("purple");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: We want to use the style property to change the color of the specified class “page."&lt;/p&gt;

&lt;p&gt;The code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;   &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Change Style&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"page"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; Welcome to my Page&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt; I like coding&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt; 
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;change&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;page&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;purple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Notice&lt;/strong&gt;:  We had to use an index to specify the index of the class we wanted to style. That is because getElementsByClassName  returns an array-like collection of elements, not a single element&lt;/p&gt;

&lt;p&gt;The output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpkb1kjl2sv59se2qlfz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpkb1kjl2sv59se2qlfz.jpg" alt="Code output" width="720" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Dom Events and Events Listener&lt;/strong&gt;: The HTML Dom allows JavaScript to react to an HTML element when an event is triggered.&lt;/p&gt;

&lt;p&gt;Events such as when a user clicks the mouse, when a web page loads, or when an input field is changed are then listened for by the Event listener, which performs the required action.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Elements&lt;/strong&gt;: This represents the HTML elements you want to add the event listener to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event&lt;/strong&gt;: It represents the event type like “click", “mouseOver", “resize”, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt;: The code that runs when the event is triggered.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;    &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Change Style&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click Me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt; 
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myBtn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Text has been changed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myBtn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we first create our function 'myBtn' that changes the text to 'Text has been changed.' Next, we attach the event listener to our button, specifying the event we want to handle, which is the 'click' event. Finally, we call our function 'myBtn' to execute the desired action when the button is clicked.&lt;/p&gt;

&lt;p&gt;The Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsxfur1p914oetluh0ozv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsxfur1p914oetluh0ozv.jpg" alt="The output of our code" width="720" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice we changed the text after we clicked the button.&lt;/p&gt;

&lt;p&gt;For further comprehensive notes on Event listeners, check out this &lt;a href="https://www.w3schools.com/js/js_events.asp" rel="noopener noreferrer"&gt;article&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we examined the Document Object Model (DOM) concept.&lt;br&gt;
 We discussed tasks like applying styles, modifying content, and associating event listeners with elements.&lt;br&gt;
 I hope you found this tutorial enjoyable, and I encourage you to solidify your understanding by practicing the discussed methods. &lt;/p&gt;

&lt;p&gt;See you at the top!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Essential ES6 JavaScript Features Every JavaScript Developer Should Know</title>
      <dc:creator>Gloria Tejuosho </dc:creator>
      <pubDate>Wed, 01 May 2024 11:03:25 +0000</pubDate>
      <link>https://dev.to/gloriasilver/essential-es6-javascript-features-every-javascript-developer-should-know-ehj</link>
      <guid>https://dev.to/gloriasilver/essential-es6-javascript-features-every-javascript-developer-should-know-ehj</guid>
      <description>&lt;p&gt;As a developer, it's crucial to stay updated with recent technologies to remain relevant and streamline development processes. The newer the technology, the less work is required. That's why we'll be discussing the essential features of ES6 that you need to master.&lt;/p&gt;

&lt;p&gt;In this article, we will examine the ES6 key features such as template literals, arrow function, Object and Array destructuring, and other related concepts within the context of functional programming paradigms in JavaScript ES6.&lt;/p&gt;

&lt;p&gt;Before proceeding with this article, it's important to have a basic understanding of JavaScript, including variables, data types, control flow, and functions. If you're not familiar with these concepts or need a refresher, check out this article by MDN web docs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ECMASCRIPT6&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ES6, short for ECMAScript 6, was developed to standardize JavaScript further, representing the sixth iteration of ECMAScript. &lt;/p&gt;

&lt;p&gt;JavaScript ES6 introduces new syntax, enabling us to write less code for accomplishing complex tasks. Understanding ES6 features facilitates efficient coding.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Key Features we will be looking at in this article: &lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Arrow function&lt;/li&gt;
&lt;li&gt;Template literals&lt;/li&gt;
&lt;li&gt;Object &lt;/li&gt;
&lt;li&gt;Array destructuring&lt;/li&gt;
&lt;li&gt;Set&lt;/li&gt;
&lt;li&gt;Spread operator&lt;/li&gt;
&lt;li&gt;Rest operator&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Arrow function&lt;/strong&gt;: Arrow functions provide a simpler and more straightforward method for creating functions compared to the traditional approach of using the 'function' keyword for declaration.&lt;/p&gt;

&lt;p&gt;Arrow function syntax: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0nb52t8zwjyhf3u8izwx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0nb52t8zwjyhf3u8izwx.jpg" alt=" " width="720" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Traditional vs Arrow function&lt;/p&gt;

&lt;p&gt;The example below shows how traditional functions and arrow functions differ in their syntax.&lt;/p&gt;

&lt;p&gt;The traditional way of declaring a function:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3cr437i7idj6c0u7jj3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3cr437i7idj6c0u7jj3.jpg" alt=" " width="720" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Arrow function: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F907vc15xy5tvlj9f2jtv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F907vc15xy5tvlj9f2jtv.jpg" alt=" " width="720" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the two methods perform the same function, but the arrow function provides a simpler way of declaring the function&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Template literals&lt;/strong&gt;: Template literals are a feature that allows you to embed expressions within string literals. Instead of concatenating strings using the '+' operator, template literals enclose the strings in backticks (&lt;code&gt;&lt;/code&gt;) and utilize ${} to serve as placeholders.&lt;/p&gt;

&lt;p&gt;Example: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil1bs0ma1kzbl8dwwopb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil1bs0ma1kzbl8dwwopb.jpg" alt=" " width="720" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NB: We no longer need to concatenate strings when accessing the values of &lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt;. Instead, we can directly use &lt;code&gt;${}&lt;/code&gt; placeholders to access them.&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Array Destructuring:&lt;/strong&gt; In ES6, array destructuring involves extracting values from an array and assigning them to separate variables.&lt;/p&gt;

&lt;p&gt;Take a look at the example below:&lt;/p&gt;

&lt;p&gt;Previously, accessing the values in the 'studentName' array was achieved using the following method:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9x8cgbnheujunsgixmzp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9x8cgbnheujunsgixmzp.jpg" alt=" " width="720" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But Array destructuring offers a straightforward approach to accessing values, requiring only a few simple steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdg5rzmqxfxd44kr8mhoa.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdg5rzmqxfxd44kr8mhoa.jpg" alt=" " width="720" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Object Destructuring&lt;/strong&gt;: This works like array destructuring, but instead of arrays, it's about pulling out values from objects.&lt;/p&gt;

&lt;p&gt;An example of object Destructuring&lt;/p&gt;

&lt;p&gt;Previously, if we wanted to extract data from 'StudentDetail', we would have done so by:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81ijqnv08hq9s4dxd2wu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81ijqnv08hq9s4dxd2wu.jpg" alt=" " width="720" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With object destructuring, accessing them becomes easier using the following method:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg85lc0e6y2ra6xoo86y2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg85lc0e6y2ra6xoo86y2.jpg" alt=" " width="720" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Set&lt;/strong&gt;: The Set method is used to retrieve only unique values from an array. It ensures that each value occurs only once within the set.&lt;/p&gt;

&lt;p&gt;Set Syntax: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiifd6sh2ozwdlulrpjk3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiifd6sh2ozwdlulrpjk3.jpg" alt=" " width="720" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example: The “games" variable holds value for different kinds of games played; the &lt;code&gt;new Set&lt;/code&gt; method can be used to return unique values ensuring no game appears more than once.&lt;/p&gt;

&lt;p&gt;-&amp;gt; Spread operator: The 'Spread' operator iterates over an iterable element, such as a string, array, or object, and then spreads each value into individual items. This allows us to quickly copy them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spread syntax&lt;/strong&gt;: (...)&lt;/p&gt;

&lt;p&gt;Example: Spread operator allows us to split the elements in ‘hobby’ variables into a single item.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7qf0yc72xug5z09rh2o1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7qf0yc72xug5z09rh2o1.jpg" alt=" " width="800" height="1199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example 2: We can use the spread operator in an array too:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsihq9cedvq8kt2c0w51h.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsihq9cedvq8kt2c0w51h.jpg" alt=" " width="800" height="1199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; &lt;strong&gt;Rest operator&lt;/strong&gt;: The Rest operator has a similar syntax as the Spread operator. However, the Rest operator is used to gather the rest of the item into an array. It allows you to access the rest of the values in an element easily.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rest Syntax&lt;/strong&gt;:  (...) Followed by the name of the parameter. &lt;/p&gt;

&lt;p&gt;Example: We can access the first name of the students and use the rest operator to collect the remaining names of the students:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvjynii3re2y3zzm4l9tb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvjynii3re2y3zzm4l9tb.jpg" alt=" " width="800" height="1199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note!&lt;/strong&gt;&lt;br&gt;
 You can't place the rest operator at the beginning like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftezhs0b7qr43rfii92ts.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftezhs0b7qr43rfii92ts.jpg" alt=" " width="720" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will return an error if you try to use the rest operator this way!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we have talked about essential features of ES6 you need to know as a developer. We started with the Arrow function, then we moved to template literals, array and object destructuring, and other related concepts. If you've reached this section, then you should be able to implement the following topics we talked about in your next project.&lt;/p&gt;

&lt;p&gt;See you at the top!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MDN web docs&lt;br&gt;
 w3Schools &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
