<?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>Forem: Yosi Leyid</title>
    <description>The latest articles on Forem by Yosi Leyid (@yosileyid).</description>
    <link>https://forem.com/yosileyid</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%2F1018437%2F4faf178b-6779-48c0-bb1d-6c1b9ae27ff3.jpeg</url>
      <title>Forem: Yosi Leyid</title>
      <link>https://forem.com/yosileyid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/yosileyid"/>
    <language>en</language>
    <item>
      <title>How to Install Node.js as a Non-Root User Using NVM: A Step-by-Step Guide</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Fri, 03 Mar 2023 16:34:42 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/how-to-install-nodejs-as-a-non-root-user-using-nvm-a-step-by-step-guide-424e</link>
      <guid>https://forem.com/hasidicdevs/how-to-install-nodejs-as-a-non-root-user-using-nvm-a-step-by-step-guide-424e</guid>
      <description>&lt;p&gt;Node.js is a popular open-source JavaScript runtime environment that allows developers to build fast and scalable web applications. Installing Node.js as a non-root user can be challenging, especially if you don't have administrative privileges on your server. However, using Node Version Manager (nvm), you can easily install and manage multiple versions of Node.js as a non-root user.&lt;/p&gt;

&lt;p&gt;In this article, we will guide you through the process of installing Node.js using nvm as a non-root user.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Node Version Manager (nvm)?
&lt;/h2&gt;

&lt;p&gt;Node Version Manager (nvm) is a command-line tool that allows you to easily manage multiple versions of Node.js on your system. With nvm, you can install and switch between different versions of Node.js without affecting the system-wide installation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why install Node.js as a non-root user?
&lt;/h2&gt;

&lt;p&gt;By default, Node.js is installed as a system-wide package, which means that it requires administrative privileges to install or update. This can be problematic if you don't have root access to your server or if you're working on a shared server.&lt;/p&gt;

&lt;p&gt;Installing Node.js as a non-root user allows you to install and manage multiple versions of Node.js without needing administrative privileges. It also ensures that your Node.js installation does not interfere with other users or applications on the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing nvm
&lt;/h2&gt;

&lt;p&gt;The first step in installing Node.js as a non-root user is to install nvm on your system. To install nvm, follow these steps:&lt;/p&gt;

&lt;p&gt;Open a terminal window on your system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Download the nvm installation script using curl or wget:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-o-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-qO-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will download the nvm installation script from the official nvm GitHub repository and execute it.&lt;/p&gt;

&lt;p&gt;Close and reopen your terminal window or run the following command to apply the changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will load the nvm script into your current shell session.&lt;/p&gt;

&lt;p&gt;Verify that nvm has been installed correctly by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command should return the current version of nvm installed on your system, which should be v0.39.3&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Node.js
&lt;/h2&gt;

&lt;p&gt;Now that nvm is installed on your system, you can use it to install any version of Node.js as a non-root user. To install a specific version of Node.js, follow these steps:&lt;/p&gt;

&lt;p&gt;List the available Node.js versions by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm ls-remote
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will display a list of all available Node.js versions that you can install using nvm.&lt;/p&gt;

&lt;p&gt;Choose the version of Node.js that you want to install and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install&lt;/span&gt; &amp;lt;version&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace  with the version of Node.js that you want to install (e.g., nvm install 14.17.0).&lt;/p&gt;

&lt;p&gt;This command will download and install the specified version of Node.js on your system.&lt;/p&gt;

&lt;p&gt;Verify that Node.js has been installed correctly by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;--v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command should return the version of Node.js that you just installed.&lt;/p&gt;

&lt;p&gt;Switching between Node.js versions&lt;/p&gt;

&lt;p&gt;With nvm, you can easily switch between different versions of Node.js on your system. To switch to a different version of Node.js, follow these steps:&lt;/p&gt;

&lt;p&gt;List all installed versions of Node.js by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will display a list of all installed versions of Node.js on your system.&lt;/p&gt;

&lt;p&gt;Choose the version of Node.js that you want to use and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;nvm&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nv"&gt;version&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace  with the version of Node.js that you want to use (e.g., nvm use 14.17.0).&lt;/p&gt;

&lt;p&gt;This command will switch your current shell session to use the specified version of Node.js.&lt;/p&gt;

&lt;p&gt;Verify that you are now using the correct version of Node.js by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command should return the version of Node.js that you just switched to.&lt;/p&gt;

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

&lt;p&gt;In conclusion, installing Node.js as a non-root user using nvm is a straightforward process that allows you to install and manage multiple versions of Node.js on your system without needing administrative privileges. With nvm, you can easily switch between different versions of Node.js, ensuring that your Node.js installation is always up-to-date and compatible with your application's requirements.&lt;/p&gt;

&lt;p&gt;When working with Node.js applications, it's essential to keep your Node.js installation up-to-date and secure. With nvm, you can easily upgrade to the latest version of Node.js or switch back to an earlier version if necessary.&lt;/p&gt;

&lt;p&gt;Remember to always verify the integrity of the Node.js installation and only install versions from trusted sources. With these precautions in place, you can enjoy the full benefits of Node.js and build fast, scalable, and secure web applications.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>nvm</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Client-Side vs. Server-Side Scripting: Understanding the Differences for Web Development</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Wed, 22 Feb 2023 02:16:30 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/client-side-vs-server-side-scripting-understanding-the-differences-for-web-development-jp2</link>
      <guid>https://forem.com/hasidicdevs/client-side-vs-server-side-scripting-understanding-the-differences-for-web-development-jp2</guid>
      <description>&lt;p&gt;In web development, there are two primary methods of processing and delivering data: client-side and server-side. Each approach has its unique advantages and limitations, and understanding the difference between the two is essential for creating efficient and effective web applications.&lt;/p&gt;

&lt;p&gt;Client-side scripting refers to the code that runs on the user's computer or device in a web browser. Client-side scripts are written in languages such as JavaScript, which is commonly used to manipulate and modify the user interface and interact with server-side scripts. In contrast, server-side scripting refers to code that runs on the server, which receives client requests, processes them, and returns a response to the client. Server-side scripts are typically written in languages like PHP, Python, Ruby, or Java.&lt;/p&gt;

&lt;p&gt;The primary difference between client-side and server-side scripting is the location where the code runs. Client-side scripts are executed on the user's computer, while server-side scripts are executed on the server. This fundamental difference affects how each type of script handles tasks such as data processing, user interaction, and security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Client-side scripting
&lt;/h2&gt;

&lt;p&gt;Client-side scripting is used to improve the user experience by providing dynamic and interactive web pages. Some common examples of client-side scripting include form validation, AJAX, and dynamic page updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Form validation
&lt;/h3&gt;

&lt;p&gt;Form validation is a process where user inputs are checked for accuracy and completeness before they are submitted to the server. Client-side scripting is commonly used for form validation because it provides immediate feedback to the user, without requiring a round-trip to the server. The following example uses JavaScript to validate a form field for a valid email address:&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;function&lt;/span&gt; &lt;span class="nf"&gt;validateEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;re&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\S&lt;/span&gt;&lt;span class="sr"&gt;+@&lt;/span&gt;&lt;span class="se"&gt;\S&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;\.\S&lt;/span&gt;&lt;span class="sr"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;email&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;h3&gt;
  
  
  AJAX
&lt;/h3&gt;

&lt;p&gt;AJAX stands for Asynchronous JavaScript and XML and is a technique used to load content into a web page without refreshing the entire page. This method improves the user experience and reduces server load by making small requests for data as needed. The following example shows how to load content using AJAX:&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;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data.php&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;success&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;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dynamic page updates
&lt;/h2&gt;

&lt;p&gt;Dynamic page updates allow web pages to change content without requiring a full page reload. This feature improves the user experience by providing fast and smooth transitions between different states of a web page. The following example shows how to use jQuery to update content dynamically:&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;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;click&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;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New content&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;h2&gt;
  
  
  Server-side scripting
&lt;/h2&gt;

&lt;p&gt;Server-side scripting is used to perform tasks that require data processing, database access, and user authentication. Server-side scripts can interact with the file system, databases, and other system resources that are not available to client-side scripts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data processing
&lt;/h3&gt;

&lt;p&gt;Server-side scripts are commonly used to process and manipulate data before returning it to the client. For example, a server-side script might process data from a form, validate it, and insert it into a database. The following example shows how to use PHP to process a form and insert the data into a database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nv"&gt;$email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Insert data into the database&lt;/span&gt;
&lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"INSERT INTO users (name, email) VALUES ('&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;', '&lt;/span&gt;&lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="s2"&gt;')"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mysqli_query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$conn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Database access
&lt;/h3&gt;

&lt;p&gt;Server-side scripts are also used to interact with databases, retrieving data and performing queries. Database queries can be complex and require a lot of processing power, making it more efficient to handle them on the server side. The following example shows how to use Python to access a MySQL database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mysql.connector&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Connect to the database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;mydb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;connector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yourusername&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yourpassword&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mydatabase&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Execute a query
&lt;/span&gt;
&lt;span class="n"&gt;mycursor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mydb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;mycursor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT * FROM customers&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mycursor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchall&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  User authentication
&lt;/h3&gt;

&lt;p&gt;Server-side scripts are also used to perform user authentication, ensuring that only authorized users can access restricted areas of a web application. User authentication is a critical security feature that helps protect sensitive data and resources. The following example shows how to use Ruby on Rails to implement user authentication:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SessionsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;email: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:session&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="ss"&gt;:email&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;downcase&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:session&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="ss"&gt;:password&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
      &lt;span class="n"&gt;log_in&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;
      &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="n"&gt;flash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:danger&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Invalid email/password combination'&lt;/span&gt;
      &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="s1"&gt;'new'&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;destroy&lt;/span&gt;
    &lt;span class="n"&gt;log_out&lt;/span&gt;
    &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="n"&gt;root_url&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;In conclusion, client-side scripting and server-side scripting are two fundamental approaches to web development that have distinct advantages and limitations. Client-side scripting is used to enhance the user experience, providing dynamic and interactive web pages that respond to user input in real-time. Server-side scripting is used to perform data processing, interact with databases, and implement security features such as user authentication. Understanding the difference between client-side and server-side scripting is crucial for creating efficient and effective web applications.&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Creating a Gemfile for a Jekyll Plugin: A Step-by-Step Guide</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Wed, 22 Feb 2023 01:10:17 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/creating-a-gemfile-for-a-jekyll-plugin-a-step-by-step-guide-oka</link>
      <guid>https://forem.com/hasidicdevs/creating-a-gemfile-for-a-jekyll-plugin-a-step-by-step-guide-oka</guid>
      <description>&lt;p&gt;If you are new to Jekyll, it is a popular static site generator that is used to build websites. Jekyll is built on Ruby, which means that you can write plugins for Jekyll using the Ruby programming language.&lt;/p&gt;

&lt;p&gt;Before we dive into creating a Gemfile for a Jekyll plugin, let's first talk about what a Gemfile is. A Gemfile is a file that lists the gems, or Ruby packages, that your application or plugin depends on. Gems are packages of Ruby code that can be installed on your computer and used in your Ruby projects. A Gemfile makes it easy to manage your project's dependencies, so you don't have to worry about installing and updating each gem manually.&lt;/p&gt;

&lt;p&gt;Now that we have a basic understanding of what a Gemfile is, let's talk about how to create one for a Jekyll plugin.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a new directory for your Jekyll plugin
&lt;/h3&gt;

&lt;p&gt;The first step in creating a Gemfile for a Jekyll plugin is to create a new directory for your plugin. You can name this directory whatever you like, but it's a good idea to name it something descriptive of your plugin.&lt;/p&gt;

&lt;p&gt;For example, if you are creating a plugin that adds social media sharing buttons to your Jekyll site, you might name your directory "jekyll-social-sharing". To create a new directory in your terminal, navigate to the directory where you want to create the new directory, and type the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;jekyll-social-sharing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Initialize a new Git repository
&lt;/h3&gt;

&lt;p&gt;Next, you will want to initialize a new Git repository in your plugin directory. This will allow you to easily track changes to your code and collaborate with other developers.&lt;/p&gt;

&lt;p&gt;To initialize a new Git repository, navigate to your plugin directory in your terminal and type the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Create a new Gemfile
&lt;/h3&gt;

&lt;p&gt;Now that you have a directory for your plugin and a Git repository initialized, you can create a new Gemfile for your plugin. To do this, navigate to your plugin directory in your terminal and type the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;Gemfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new file called "Gemfile" in your plugin directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Add dependencies to your Gemfile
&lt;/h3&gt;

&lt;p&gt;Once you have created a Gemfile for your plugin, you can start adding dependencies to it. Dependencies are gems that your plugin relies on to function correctly. You can add dependencies to your Gemfile by specifying the gem name and version number, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"https://rubygems.org"&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"jekyll"&lt;/span&gt;
&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="s2"&gt;"sass"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we are adding two dependencies to our Gemfile: "jekyll" and "sass". The "source" line specifies where to download the gems from (in this case, the official RubyGems repository), and the "gem" lines specify the names and versions of the gems to install.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Install dependencies
&lt;/h3&gt;

&lt;p&gt;Once you have added dependencies to your Gemfile, you need to install them. To do this, navigate to your plugin directory in your terminal and type the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will install all of the gems specified in your Gemfile, as well as any dependencies that those gems rely on. If this is the first time you have run "bundle install" in your plugin directory, it may take a few minutes to download and install all of the necessary gems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Use dependencies in your plugin code
&lt;/h3&gt;

&lt;p&gt;Now that you have installed your plugin's dependencies, you can start using them in your plugin code. For example, if your plugin relies on the "jekyll"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"jekyll"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will allow you to use the functionality provided by the "jekyll" gem in your plugin code.&lt;/p&gt;

&lt;p&gt;Here is an example of a simple Jekyll plugin that uses the "jekyll" and "sass" gems:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# jekyll-social-sharing.rb&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"jekyll"&lt;/span&gt;
&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"sass"&lt;/span&gt;

&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Jekyll&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SocialSharing&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Liquid&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Tag&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tag_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;super&lt;/span&gt;
      &lt;span class="vi"&gt;@text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="s2"&gt;"&amp;lt;div class='social-sharing'&amp;gt;
        &amp;lt;a href='https://twitter.com/share' class='twitter-share-button'&amp;gt;Tweet&amp;lt;/a&amp;gt;
        &amp;lt;a href='https://www.facebook.com/sharer/sharer.php?u=&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'page'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;' class='facebook-share-button'&amp;gt;Share on Facebook&amp;lt;/a&amp;gt;
      &amp;lt;/div&amp;gt;"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="no"&gt;Liquid&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register_tag&lt;/span&gt; &lt;span class="s2"&gt;"social_sharing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we are creating a new Liquid tag called "social_sharing" that generates social media sharing buttons for Twitter and Facebook. We are using the "jekyll" gem to access the Liquid template engine and the "sass" gem to style the buttons.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Test your plugin
&lt;/h3&gt;

&lt;p&gt;Once you have written your plugin code and installed all of the necessary gems, it's a good idea to test your plugin to make sure it works as expected. To do this, you can run your Jekyll site with the "jekyll serve" command and check that your plugin is working correctly.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If everything is working correctly, you should be able to see the social media sharing buttons on your Jekyll site.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 8: Publish your plugin
&lt;/h3&gt;

&lt;p&gt;Once you have tested your plugin and made sure it works correctly, you may want to publish it so that others can use it. You can publish your plugin to the official RubyGems repository by creating a new account on &lt;a href="https://rubygems.org"&gt;https://rubygems.org&lt;/a&gt; and following the instructions for publishing a gem.&lt;/p&gt;

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

&lt;p&gt;Congratulations! You have now learned how to create a Gemfile for a Jekyll plugin. By following these steps, you can easily manage your plugin's dependencies and ensure that your plugin works correctly. Remember to test your plugin thoroughly before publishing it, and to follow best practices for writing and publishing Ruby gems. Good luck!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Build Your Own API with Hoppscotch: Tips and Best Practices</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Mon, 20 Feb 2023 18:40:42 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/build-your-own-api-with-hoppscotch-tips-and-best-practices-20em</link>
      <guid>https://forem.com/hasidicdevs/build-your-own-api-with-hoppscotch-tips-and-best-practices-20em</guid>
      <description>&lt;p&gt;Creating a new API can be a complex process, involving many different steps and technologies. However, with the right platform, this process can be made much simpler. Hoppscotch is an open-source API development platform that simplifies the entire API development process, allowing developers to create, test, and document APIs quickly and easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started with Hoppscotch
&lt;/h2&gt;

&lt;p&gt;To get started with Hoppscotch, the first step is to sign up for an account. Once you have signed up, you will be taken to the Hoppscotch dashboard, where you can create a new project.&lt;/p&gt;

&lt;p&gt;To create a new project, click on the "New Project" button on the dashboard. You will be prompted to enter a name for your project and a description. Once you have entered this information, click on the "Create Project" button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a new API endpoint
&lt;/h2&gt;

&lt;p&gt;With your project created, you can now create a new API endpoint. To do this, click on the "New API" button on the project dashboard. You will be prompted to enter a name for your API and a description.&lt;/p&gt;

&lt;p&gt;Once you have entered this information, you will be taken to the API editor, where you can start building your API endpoint. The editor is divided into three sections: Headers, Body, and Tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Headers
&lt;/h2&gt;

&lt;p&gt;In the Headers section, you can add any headers that you want to include in your API request. Headers are used to provide additional information about the request, such as the content type or authorization credentials.&lt;/p&gt;

&lt;p&gt;Here is an example of how to add a header to an API request using Hoppscotch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api HTTP/1.1
Host: example.com
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Content-Type: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add a new header in Hoppscotch, click on the "Add Header" button. You will be prompted to enter the name and value of the header. Once you have entered this information, click on the "Add" button to add the header to your API request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Body
&lt;/h2&gt;

&lt;p&gt;In the Body section, you can add the data that you want to send with your API request. This can include JSON data, form data, or any other type of data that your API endpoint requires.&lt;/p&gt;

&lt;p&gt;Here is an example of how to add JSON data to an API request using Hoppscotch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;POST /api HTTP/1.1
Host: example.com
Content-Type: application/json

&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"name"&lt;/span&gt;: &lt;span class="s2"&gt;"John Smith"&lt;/span&gt;,
    &lt;span class="s2"&gt;"age"&lt;/span&gt;: 30,
    &lt;span class="s2"&gt;"email"&lt;/span&gt;: &lt;span class="s2"&gt;"john.smith@example.com"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add a new data field in Hoppscotch, click on the "Add Field" button. You will be prompted to enter the name and value of the data field. Once you have entered this information, click on the "Add" button to add the data field to your API request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests
&lt;/h2&gt;

&lt;p&gt;In the Tests section, you can write tests that will be run after your API request has been sent. These tests can be used to verify that your API endpoint is working correctly.&lt;/p&gt;

&lt;p&gt;Here is an example of how to write a test using Hoppscotch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tests["Status code is 200"] = responseCode.code === 200;
tests["Response time is less than 500ms"] = responseTime &amp;lt; 500;
tests["Response contains expected data"] = responseBody.has("Hello, World!");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add a new test in Hoppscotch, click on the "Add Test" button. You will be prompted to enter a name for the test and the test code. Once you have entered this information, click on the "Add" button to add the test to your API request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing your API endpoint
&lt;/h2&gt;

&lt;p&gt;Once you have created your API endpoint, you can test it using Hoppscotch's built-in testing tools. To do this, simply click on the "Send" button in the API editor.&lt;/p&gt;

&lt;p&gt;Hoppscotch will then send your API request and display the response in the "Response" section of the editor. If there are any errors or issues with your API request, Hoppscotch will display an error message.&lt;/p&gt;

&lt;p&gt;If your API request was successful, you can use the response data to further develop and refine your API endpoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Documenting your API endpoint
&lt;/h2&gt;

&lt;p&gt;Finally, once you have created and tested your API endpoint, you can document it using Hoppscotch's documentation tools. To do this, click on the "Docs" button on the project dashboard.&lt;/p&gt;

&lt;p&gt;In the documentation editor, you can enter information about your API endpoint, such as its purpose, expected inputs and outputs, and any other relevant information.&lt;/p&gt;

&lt;p&gt;Here is an example of how to document an API endpoint using Hoppscotch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## API Endpoint: /api&lt;/span&gt;

&lt;span class="gu"&gt;### Purpose&lt;/span&gt;

This API endpoint is used to retrieve data from the server.

&lt;span class="gu"&gt;### Inputs&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; None

&lt;span class="gu"&gt;### Outputs&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; Data (JSON)

&lt;span class="gu"&gt;### Example&lt;/span&gt;

Request:

GET /api HTTP/1.1
Host: example.com

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "name": "John Smith",
    "age": 30,
    "email": "john.smith@example.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have entered this information, click on the "Save" button to save your API endpoint documentation.&lt;/p&gt;

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

&lt;p&gt;With Hoppscotch, creating a new API endpoint is a simple and straightforward process. By using Hoppscotch's API development, testing, and documentation tools, you can quickly and easily create a robust and reliable API endpoint that meets your organization's needs.&lt;/p&gt;

&lt;p&gt;With its intuitive user interface, powerful testing tools, and comprehensive documentation features, Hoppscotch is an essential tool for any developer looking to create high-quality APIs. So why not give it a try today and see how easy it can be to create a new API endpoint using Hoppscotch!&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.hoppscotch.io/"&gt;Hoppscotch Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/hoppscotch"&gt;Hoppscotch Github Org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hoppscotch.io/"&gt;Try Hoppscotch Now&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>api</category>
    </item>
    <item>
      <title>Introducing PolygonDB: A Modern and Flexible Alternative to MongoDB with Advanced Data Management Features</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Sun, 19 Feb 2023 19:15:44 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/introducing-polygondb-a-modern-and-flexible-alternative-to-mongodb-with-advanced-data-management-features-50kl</link>
      <guid>https://forem.com/hasidicdevs/introducing-polygondb-a-modern-and-flexible-alternative-to-mongodb-with-advanced-data-management-features-50kl</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/JewishLewish/PolygonDB"&gt;PolygonDB&lt;/a&gt; is an open-source database management system that is designed to be a modern alternative to MongoDB. It's built in Rust, a programming language known for its speed and reliability, and it boasts a number of features that make it a compelling choice for developers who need to store and manage data.&lt;/p&gt;

&lt;p&gt;One of the key features of PolygonDB is its support for complex data types. Let's say, for example, that you're building an e-commerce site and you need to store information about each product. In MongoDB, you might create a collection for products and store each product as a document, like this:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ObjectId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;612f4a4d9a4ce4d4a3a0e3fe&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;name&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;iPhone 13 Pro&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;description&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;The latest and greatest iPhone&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;price&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;999.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;color&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;Graphite&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;storage&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;128GB&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;This works fine, but what if you need to store additional information about each product, such as customer reviews or a list of related products? In MongoDB, you would have to store this information as nested documents or arrays, which can get messy and difficult to work with.&lt;/p&gt;

&lt;p&gt;With PolygonDB, you can store each product as a YAML or TOML file, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;name = "iPhone 13 Pro"&lt;/span&gt;
&lt;span class="s"&gt;description = "The latest and greatest iPhone"&lt;/span&gt;
&lt;span class="s"&gt;price = &lt;/span&gt;&lt;span class="m"&gt;999.99&lt;/span&gt;
&lt;span class="s"&gt;color = "Graphite"&lt;/span&gt;
&lt;span class="s"&gt;storage = "128GB"&lt;/span&gt;
&lt;span class="s"&gt;reviews = ["612f4ad69a4ce4d4a3a0e4ff", "612f4ae69a4ce4d4a3a0e54c"]&lt;/span&gt;
&lt;span class="s"&gt;related_products = ["612f4b099a4ce4d4a3a0e5c4", "612f4b209a4ce4d4a3a0e60f"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes it much easier to work with complex data types, since you can use familiar file-based operations to read, write, and manipulate data.&lt;/p&gt;

&lt;p&gt;Another key feature of PolygonDB is its support for transactions. Let's say, for example, that you're building a banking app and you need to ensure that transfers between accounts are atomic and consistent. With PolygonDB, you can use transactions to ensure that all changes are committed or rolled back together, so that you don't end up with inconsistent or corrupted data.&lt;/p&gt;

&lt;p&gt;Here's an example of how you might use transactions in PolygonDB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;txn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="nf"&gt;.transaction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;account_a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;txn&lt;/span&gt;&lt;span class="nf"&gt;.get_document&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"accounts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"account_123"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;account_b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;txn&lt;/span&gt;&lt;span class="nf"&gt;.get_document&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"accounts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"account_456"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;account_a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"balance"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;transfer_amount&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_balance_a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;account_a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"balance"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;transfer_amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;new_balance_b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;account_b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"balance"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;transfer_amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;txn&lt;/span&gt;&lt;span class="nf"&gt;.update_document&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"accounts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"account_123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"balance"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new_balance_a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="n"&gt;txn&lt;/span&gt;&lt;span class="nf"&gt;.update_document&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"accounts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"account_456"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"balance"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new_balance_b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="n"&gt;txn&lt;/span&gt;&lt;span class="nf"&gt;.commit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&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="n"&gt;txn&lt;/span&gt;&lt;span class="nf"&gt;.rollback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code retrieves two documents from the "accounts" collection, checks that there is enough money in one account to make a transfer, and then updates both documents atomically. If there is not enough money, the transaction is rolled back.&lt;/p&gt;

&lt;p&gt;Finally, PolygonDB has built-in support for indexing, which makes it easy to perform complex queries and sort data. You can create indexes on one or more fields, and PolygonDB will automatically maintain the index as you add, remove, or modify documents. This can greatly improve the performance of your queries, especially for large collections.&lt;/p&gt;

&lt;p&gt;Here's an example of how you might create an index in PolygonDB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="nf"&gt;.create_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"products"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code creates an index on the "name" field in the "products" collection. Now, when you perform a query that includes the "name" field, PolygonDB will use the index to quickly find matching documents.&lt;/p&gt;

&lt;p&gt;In summary, PolygonDB is a modern and flexible database management system that offers a number of features that make it a compelling alternative to MongoDB. Its support for complex data types, transactions, and indexing make it a powerful tool for developers who need to store and manage data. If you're interested in learning more, I encourage you to check out the PolygonDB code base and documentation on GitHub.&lt;/p&gt;

</description>
      <category>json</category>
      <category>database</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Mastering Object-Oriented Programming in JavaScript: Best Practices and Examples</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Sun, 19 Feb 2023 16:28:18 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/mastering-object-oriented-programming-in-javascript-best-practices-and-examples-31mc</link>
      <guid>https://forem.com/hasidicdevs/mastering-object-oriented-programming-in-javascript-best-practices-and-examples-31mc</guid>
      <description>&lt;p&gt;Object-Oriented Programming (OOP) is a popular programming paradigm that allows developers to create modular, maintainable, and reusable code. JavaScript, a programming language that has become ubiquitous in web development, also supports OOP. In this blog post, we will explore OOP in JavaScript and how it can be used to write more organized, efficient, and scalable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Object-Oriented Programming?
&lt;/h2&gt;

&lt;p&gt;Object-Oriented Programming is a programming paradigm that is based on the concept of objects. An object is a collection of data and behaviors that are defined by a set of properties and methods. OOP is centered around the idea that software systems are composed of objects that interact with each other to achieve a common goal.&lt;/p&gt;

&lt;p&gt;OOP has four fundamental concepts that make it a powerful tool for software development: Encapsulation, Abstraction, Inheritance, and Polymorphism.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encapsulation:&lt;/strong&gt; Encapsulation is the process of hiding the internal details of an object and exposing only the necessary information to the outside world. This is achieved by defining the properties and methods of an object as public or private. Private members are only accessible within the object, while public members can be accessed from outside the object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Abstraction:&lt;/strong&gt; Abstraction is the process of simplifying complex systems by creating models that capture the essential features of the system while hiding unnecessary details. In OOP, this is achieved by defining abstract classes and interfaces that define the common properties and behaviors of a group of objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inheritance:&lt;/strong&gt; Inheritance is the process of creating new classes from existing classes. The new class inherits the properties and behaviors of the parent class, and can add new properties and behaviors or override existing ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Polymorphism:&lt;/strong&gt; Polymorphism is the ability of objects to take on multiple forms or behaviors. In OOP, this is achieved by using interfaces and abstract classes to define the common properties and behaviors of a group of objects, while allowing each object to implement them in its own way.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript and OOP
&lt;/h2&gt;

&lt;p&gt;JavaScript was originally designed as a scripting language for web pages. However, with the advent of Node.js, JavaScript has become a full-fledged programming language that can be used to create complex systems.&lt;/p&gt;

&lt;p&gt;JavaScript supports OOP, but in a different way than other programming languages like Java or C++. In JavaScript, objects are created using a constructor function or an object literal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Constructor Functions
&lt;/h2&gt;

&lt;p&gt;A constructor function is a special function that is used to create new objects. It is called using the "new" keyword, which creates a new object and assigns it to the "this" keyword. The constructor function can define properties and methods on the object using the "this" keyword.&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;function&lt;/span&gt; &lt;span class="nf"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt; &lt;span class="o"&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="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, my name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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; and I am &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; years old.&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;john&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&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="nx"&gt;john&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// outputs "Hello, my name is John and I am 30 years old."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we define a constructor function called "Person" that takes two parameters, "name" and "age". We define two properties, "name" and "age", and a method called "greet" that logs a message to the console.&lt;/p&gt;

&lt;p&gt;We create a new object called "john" using the "new" keyword and pass in the arguments "John" and 30. We then call the "greet" method on the "john" object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object Literals
&lt;/h2&gt;

&lt;p&gt;Object literals are a shorthand notation for creating new objects. They are created using curly braces and can define properties and methods on the object.&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;var&lt;/span&gt; &lt;span class="nx"&gt;john&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="na"&gt;age&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;greet&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="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, my name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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; and I am &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; years old.&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;john&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// outputs "Hello, my name is John and I am 30 years old."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define an object called "john" using object literal notation. We define two properties, "name" and "age", and a method called "greet" that logs a message to the console.&lt;/p&gt;

&lt;p&gt;We then call the "greet" method on the "john" object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Classes in JavaScript
&lt;/h2&gt;

&lt;p&gt;In ES6, JavaScript introduced the class syntax, which provides a simpler and more structured way of defining objects and their behavior. Classes in JavaScript are still based on the prototype inheritance model, but they provide a more familiar syntax for developers who are used to classes in other programming languages.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&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, my name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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; and I am &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; years old.&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;john&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&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="nx"&gt;john&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// outputs "Hello, my name is John and I am 30 years old."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a class called "Person" that has a constructor function that takes two parameters, "name" and "age". We define two properties, "name" and "age", and a method called "greet" that logs a message to the console.&lt;/p&gt;

&lt;p&gt;We create a new object called "john" using the "new" keyword and pass in the arguments "John" and 30. We then call the "greet" method on the "john" object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inheritance in JavaScript
&lt;/h2&gt;

&lt;p&gt;Inheritance in JavaScript is achieved using the prototype chain. Each object in JavaScript has a prototype object, which it inherits properties and methods from. The prototype object, in turn, has a prototype object, and so on, until the top of the chain is reached, which is the Object prototype.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&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, my name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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; and I am &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; years old.&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;displaySalary&lt;/span&gt;&lt;span class="p"&gt;()&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;My salary is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;salary&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;john&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&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="mi"&gt;50000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;john&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// outputs "Hello, my name is John and I am 30 years old."&lt;/span&gt;
&lt;span class="nx"&gt;john&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;displaySalary&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// outputs "My salary is 50000"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a class called &lt;strong&gt;"Person"&lt;/strong&gt; that has a constructor function that takes two parameters, "name" and "age". We define two properties, "name" and "age", and a method called "greet" that logs a message to the console.&lt;/p&gt;

&lt;p&gt;We then define a class called &lt;strong&gt;"Employee"&lt;/strong&gt; that extends the "Person" class. We add a new property called "salary" and a method called "displaySalary".&lt;/p&gt;

&lt;p&gt;We create a new object called &lt;strong&gt;"john"&lt;/strong&gt; using the "new" keyword and pass in the arguments "John", 30, and 50000. We then call the &lt;strong&gt;"greet()"&lt;/strong&gt; method and the &lt;strong&gt;"displaySalary()"&lt;/strong&gt; method on the "john" object.&lt;/p&gt;

&lt;p&gt;The "Employee" class inherits the properties and methods of the "Person" class using the "extends" keyword. The "super" keyword is used to call the constructor of the parent class and initialize the "name" and "age" properties of the "Employee" object.&lt;/p&gt;

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

&lt;p&gt;Object-oriented programming is an important paradigm in software development, and JavaScript provides various ways to implement OOP concepts. In this blog post, we covered the basics of OOP in JavaScript, including object literals, classes, and inheritance.&lt;/p&gt;

&lt;p&gt;It's important to note that OOP is just one approach to programming, and there are other paradigms such as functional programming and procedural programming. Developers should choose the appropriate approach based on the problem they're trying to solve and the requirements of the project.&lt;/p&gt;

&lt;p&gt;By understanding OOP concepts in JavaScript, developers can write code that is more organized, modular, and reusable. This can result in more maintainable code that is easier to debug and extend over time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;Object Cheat Sheet c/o Reddit:&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%2F3hids0v5xv41zwb0gqtv.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%2F3hids0v5xv41zwb0gqtv.jpg" alt="9nxtqtho6q861" width="800" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>website</category>
    </item>
    <item>
      <title>JavaScript Classes 101: A Beginner's Guide to Object-Oriented Programming</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Fri, 17 Feb 2023 20:15:21 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/javascript-classes-101-a-beginners-guide-to-object-oriented-programming-1mek</link>
      <guid>https://forem.com/hasidicdevs/javascript-classes-101-a-beginners-guide-to-object-oriented-programming-1mek</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript is one of the most popular programming languages in use today. It is a versatile language that is used for a variety of purposes, including web development, game development, and server-side scripting. One of the most important features of JavaScript is its support for object-oriented programming (OOP), which allows developers to create classes that represent real-world objects and encapsulate their behavior and data.&lt;/p&gt;

&lt;p&gt;In this blog post, we will explore the concept of classes in JavaScript, and how they can be used to create reusable and maintainable code. We will cover the syntax and semantics of classes, as well as their relationship with objects and inheritance. We will also discuss some best practices for using classes in your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are classes in JavaScript?
&lt;/h2&gt;

&lt;p&gt;A class in JavaScript is a blueprint for creating objects. It defines the properties and methods that an object will have, as well as any behavior that the object should exhibit. Classes can be thought of as templates or prototypes for objects, which are instantiated (i.e. created) based on their class definition.&lt;/p&gt;

&lt;p&gt;Classes were introduced in ECMAScript 6, the latest version of the JavaScript language, as a way to make OOP in JavaScript more intuitive and easier to use. Prior to ECMAScript 6, developers used a combination of constructor functions and prototype chains to achieve OOP in JavaScript. Classes provide a more structured and organized way to define objects, and are designed to be more familiar to developers who are used to OOP in other programming languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  The syntax of a JavaScript class
&lt;/h2&gt;

&lt;p&gt;The syntax of a JavaScript class is relatively simple. Here is an example of a class definition:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;()&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, my name is &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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; and I am &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; years old.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class is called Person and has two properties, name and age, as well as one method, sayHello(). The constructor() method is a special method that is called when an object is created based on the class. It sets the initial values of the object's properties. The sayHello() method is a regular method that can be called on an instance of the class.&lt;/p&gt;

&lt;p&gt;To create an object based on a class, you use the new keyword, like this:&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;person1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jane&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;person1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Hello, my name is John and I am 30 years old."&lt;/span&gt;
&lt;span class="nx"&gt;person2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Hello, my name is Jane and I am 25 years old."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create two objects based on the Person class, and call the sayHello() method on each object.&lt;/p&gt;

&lt;h2&gt;
  
  
  The relationship between classes and objects
&lt;/h2&gt;

&lt;p&gt;In JavaScript, classes and objects are closely related. A class defines the properties and methods that an object will have, but an object is an instance of a class that has its own unique values for those properties. When you create an object based on a class, you are creating an instance of that class, which inherits all the properties and methods of the class.&lt;/p&gt;

&lt;p&gt;For example, if we create a class called Car:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;make&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;make&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;make&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;year&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&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;The &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;make&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; is starting.&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="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;()&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;The &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;make&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;is stopping.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Inheritance in JavaScript classes
&lt;/h2&gt;

&lt;p&gt;Inheritance is an important concept in OOP, and JavaScript classes support inheritance. Inheritance allows you to create a new class based on an existing class, which inherits all the properties and methods of the parent class. The new class can then add its own properties and methods, or override the properties and methods of the parent class.&lt;/p&gt;

&lt;p&gt;To create a subclass, you use the extends keyword, like this:&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;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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; makes a noise.&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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; barks.&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fido&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Fido barks."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create a class called Animal that has a name property and a speak() method. We then create a subclass called Dog that extends the Animal class using the extends keyword. The Dog class overrides the speak() method of the Animal class, so that it now outputs "barks" instead of "makes a noise".&lt;/p&gt;

&lt;p&gt;When we create an instance of the Dog class, it inherits the properties and methods of the Animal class, and we can call the speak() method on the Dog object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best practices for using classes in JavaScript
&lt;/h2&gt;

&lt;p&gt;Here are some best practices for using classes in your JavaScript code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use classes for creating complex objects with multiple properties and methods. If you only need a simple object with a few properties, a plain object literal may be sufficient.&lt;/li&gt;
&lt;li&gt;Use meaningful names for your classes, that describe the objects they represent. For example, if you're creating a class for a car, use the name Car.&lt;/li&gt;
&lt;li&gt;Use proper indentation and formatting to make your code more readable. This is especially important when working with classes, which can have many properties and methods.&lt;/li&gt;
&lt;li&gt;Keep your class definitions short and focused. If a class has too many properties and methods, it may be a sign that it needs to be refactored into multiple smaller classes.&lt;/li&gt;
&lt;li&gt;Use inheritance sparingly, and only when it makes sense for your use case. Overusing inheritance can lead to complex and difficult-to-maintain code.&lt;/li&gt;
&lt;li&gt;Use access modifiers such as public, private, and protected to control access to the properties and methods of your class. This can help prevent unintended changes to the state of your objects.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;JavaScript classes are a powerful feature that allow developers to create reusable and maintainable code. Classes provide a structured and organized way to define objects, and make it easier to implement OOP in JavaScript. With their support for inheritance and access modifiers, classes in JavaScript provide a flexible and powerful way to create complex and extensible code.&lt;/p&gt;

&lt;p&gt;By following best practices and using classes in a thoughtful and intentional way, you can create code that is easy to read, understand, and maintain, even as your codebase grows in complexity.&lt;/p&gt;

</description>
      <category>vibecoding</category>
    </item>
    <item>
      <title>What Is A Dynamic Website?</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Fri, 17 Feb 2023 06:22:24 +0000</pubDate>
      <link>https://forem.com/yosileyid/what-is-a-dynamic-website-pje</link>
      <guid>https://forem.com/yosileyid/what-is-a-dynamic-website-pje</guid>
      <description>&lt;p&gt;In today's digital world, a website is no longer just an online brochure or an information repository. It has become a medium for businesses and individuals to interact with their customers, showcase their products and services, and create an online presence that can help them reach a wider audience. With the advent of dynamic websites, the way websites are created and managed has changed significantly. In this blog post, we will explore what a dynamic website is, how it works, and what are its benefits.&lt;/p&gt;

&lt;p&gt;A dynamic website is a type of website that is created using dynamic web pages. In simple terms, dynamic web pages are those that are generated in real-time, based on the user's interaction with the website. Unlike static web pages, which remain the same for every user and are pre-designed, dynamic web pages are designed to adapt to the user's needs, preferences, and actions.&lt;/p&gt;

&lt;p&gt;Dynamic web pages are created using programming languages such as PHP, ASP.NET, Ruby on Rails, and many others. These languages allow developers to create web pages that can interact with databases, generate content on the fly, and provide a personalized experience for the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does a Dynamic Website Work?
&lt;/h2&gt;

&lt;p&gt;A dynamic website works by using a combination of server-side scripting, client-side scripting, and a database. When a user visits a dynamic website, the server-side scripting engine processes the request, interacts with the database to retrieve the necessary information, and generates the dynamic content. The content is then sent to the user's web browser, which uses client-side scripting to render the web page.&lt;/p&gt;

&lt;p&gt;Server-side scripting refers to the process of running code on the web server, as opposed to running it on the user's computer. This allows the website to generate dynamic content that is customized to the user's needs. The server-side scripting engine can also interact with databases, which allows the website to store and retrieve information such as user profiles, product catalogs, and customer orders.&lt;/p&gt;

&lt;p&gt;Client-side scripting, on the other hand, refers to the process of running code on the user's web browser. This allows the website to provide interactive features such as drop-down menus, pop-up windows, and dynamic forms. Client-side scripting is typically done using JavaScript, which is supported by all modern web browsers.&lt;/p&gt;

&lt;p&gt;The database is a crucial component of a dynamic website. It is used to store and retrieve information such as user profiles, product catalogs, customer orders, and other data that is necessary for the website to function. The database is typically managed using a database management system (DBMS), such as MySQL, Oracle, or Microsoft SQL Server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Dynamic Websites
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Personalized Experience:&lt;/strong&gt; One of the biggest benefits of a dynamic website is that it can provide a personalized experience for the user. By using server-side scripting and a database, the website can generate dynamic content that is customized to the user's needs. For example, an e-commerce website can recommend products based on the user's previous purchases or browsing history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive Features:&lt;/strong&gt; Another benefit of dynamic websites is that they can provide interactive features that are not possible with static websites. Client-side scripting allows the website to provide features such as drop-down menus, pop-up windows, and dynamic forms, which can make the user's experience more engaging and intuitive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content Management:&lt;/strong&gt; Dynamic websites also make it easier to manage content. With a static website, every change to the content requires editing the HTML code manually. With a dynamic website, the content can be stored in a database and edited through a content management system (CMS), which makes it easier to update the website and keep it up-to-date.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; Dynamic websites are also more scalable than static websites. As the website grows and more users visit the site, the server-side scripting engine can handle the increased traffic by generating dynamic content on the fly, without the need for additional coding. This makes it easier to add new features, functionality, and content to the website as the need arises.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Search Engine Optimization:&lt;/strong&gt; Dynamic websites are also more search engine-friendly than static websites. Since dynamic web pages are generated in real-time, the content can be optimized for search engines, which can help the website rank higher in search engine results pages (SERPs). Dynamic websites can also use a variety of tools and techniques, such as XML sitemaps and meta tags, to improve their visibility and search engine rankings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analytics:&lt;/strong&gt; Dynamic websites are also easier to track and analyze. By using analytics tools such as Google Analytics, website owners can track user behavior, identify popular pages, and monitor key metrics such as bounce rate and conversion rate. This data can be used to improve the website's performance and optimize its content and features for maximum effectiveness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integration:&lt;/strong&gt; Dynamic websites can also be integrated with other systems and applications. For example, an e-commerce website can integrate with a payment gateway to process customer orders, or with a shipping provider to manage delivery and tracking. By integrating with other systems, dynamic websites can streamline business processes, improve efficiency, and provide a more seamless user experience.&lt;/p&gt;

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

&lt;p&gt;In conclusion, a dynamic website is a type of website that is created using dynamic web pages. Dynamic web pages are generated in real-time, based on the user's interaction with the website. Dynamic websites use a combination of server-side scripting, client-side scripting, and a database to provide a personalized experience, interactive features, content management, scalability, search engine optimization, analytics, and integration.&lt;/p&gt;

&lt;p&gt;Dynamic websites offer a number of benefits over static websites, including the ability to provide a more engaging and interactive user experience, easier content management, scalability, search engine optimization, analytics, and integration with other systems and applications. As such, dynamic websites have become an essential tool for businesses and individuals looking to create a powerful online presence and engage with their customers in new and exciting ways.&lt;/p&gt;

</description>
      <category>github</category>
      <category>testing</category>
      <category>automation</category>
      <category>githubactions</category>
    </item>
    <item>
      <title>React States: Best Practices for Managing State in Your Applications</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Thu, 16 Feb 2023 20:16:25 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/react-states-best-practices-for-managing-state-in-your-applications-4pk7</link>
      <guid>https://forem.com/hasidicdevs/react-states-best-practices-for-managing-state-in-your-applications-4pk7</guid>
      <description>&lt;p&gt;React is a popular JavaScript library used for building user interfaces. One of the key concepts in React is state, which is used to manage data and make components interactive. In this blog post, we'll dive into what React states are, how they work, and how they can be used to build powerful and dynamic applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a React state?
&lt;/h2&gt;

&lt;p&gt;In simple terms, a state is an object that holds data and determines how a component should behave and render. It is like a memory that keeps track of the changes in a component's properties and allows it to be responsive to user interactions. A state is mutable and can be updated using the setState method, triggering a re-render of the component and its children.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do React states work?
&lt;/h2&gt;

&lt;p&gt;To create a state in React, we need to first define an initial state value in the constructor of our component class. The state can be a primitive data type, such as a string or number, or an object that contains multiple key-value pairs.&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;class&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;count&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="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&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="c1"&gt;// ...&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 above code, we've defined an initial state for a component called &lt;strong&gt;MyComponent&lt;/strong&gt;. It has two &lt;code&gt;properties&lt;/code&gt;, &lt;code&gt;count&lt;/code&gt; and &lt;code&gt;message&lt;/code&gt;, with initial values of &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;'Hello, world!'&lt;/code&gt; respectively. To update the state, we can call the &lt;code&gt;setState&lt;/code&gt; method, passing in an object that contains the updated key-value pairs. For example, to increment the &lt;code&gt;count&lt;/code&gt; property by &lt;code&gt;1&lt;/code&gt;, we can do:&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;setState&lt;/code&gt; is called, React will compare the new state with the previous state and make necessary updates to the component and its children. This includes updating the virtual DOM, diffing the changes, and rendering the updated component to the real DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use React states?
&lt;/h2&gt;

&lt;p&gt;React states are useful for building dynamic, interactive UIs that respond to user inputs and events. They provide a way to manage and update data within a component without requiring a full page refresh or server call. States can be used to create controlled components, which are components that have their values controlled by React, rather than the user. This allows for better data validation and error handling. For example, if we have an input field that only accepts numbers, we can use a state to validate the input and prevent the user from submitting invalid data.&lt;/p&gt;

&lt;p&gt;States can also be used to create unidirectional data flow, where the data flows in a single direction from parent to child components. This makes it easier to reason about the data and reduces the likelihood of bugs caused by conflicting state changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best practices for using React states
&lt;/h2&gt;

&lt;p&gt;To use React states effectively, it's important to follow some best practices that will ensure optimal performance and maintainability of your code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep states minimal
&lt;/h3&gt;

&lt;p&gt;States should only contain data that is essential for rendering the component. It's important to avoid putting too much data into a state, as this can cause performance issues and make the code harder to maintain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Avoid cascading states
&lt;/h3&gt;

&lt;p&gt;Cascading states occur when a state is passed down through multiple levels of components, resulting in the need for multiple props and setState calls. This can lead to code that is hard to read and maintain. To avoid cascading states, consider using a state management library like Redux or MobX.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use functional components
&lt;/h3&gt;

&lt;p&gt;Functional components are simpler and easier to read than class components, and they provide better performance. Since functional components don't have a state, they rely on &lt;code&gt;props&lt;/code&gt; to render. This makes it easier to reason about the data and ensures that the data flows in a unidirectional way, from parent to child components. Functional components are also easier to test, since they are pure functions that only take in &lt;code&gt;props&lt;/code&gt; and return a JSX element. This makes it easier to write unit tests and ensure that the component behaves as expected.&lt;/p&gt;

&lt;p&gt;Functional components can also use hooks, which are a powerful mechanism for managing state and other side effects in React. Hooks allow us to use state and other React features without the need for a class component. They provide a simple and intuitive way to manage state, handle effects, and perform other common tasks in React. Overall, functional components are a great choice for building simple, reusable, and performant components in React. They provide a simpler and more intuitive way to build components and help ensure that our code is maintainable, scalable, and easy to test&lt;/p&gt;

&lt;h3&gt;
  
  
  Use immutability
&lt;/h3&gt;

&lt;p&gt;When updating a state, it's important to do so immutably. This means creating a new object with the updated data, rather than directly modifying the existing state. This ensures that React can detect the changes and re-render the component and its children as needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Optimize re-renders
&lt;/h3&gt;

&lt;p&gt;Since re-rendering a component can be a performance-intensive operation, it's important to optimize the re-renders as much as possible. One way to do this is to use the shouldComponentUpdate lifecycle method, which allows us to determine if a component should re-render or not. By implementing this method, we can skip unnecessary re-renders and improve the overall performance of the application.&lt;/p&gt;

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

&lt;p&gt;React states are an essential part of building dynamic, interactive user interfaces. By managing data and allowing components to respond to user interactions, states provide a powerful mechanism for building robust and responsive applications. By following best practices and optimizing our code, we can ensure that our React applications are performant, maintainable, and scalable.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Using React "States"</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Thu, 16 Feb 2023 01:13:02 +0000</pubDate>
      <link>https://forem.com/hasidicdevs/using-react-states-4kak</link>
      <guid>https://forem.com/hasidicdevs/using-react-states-4kak</guid>
      <description>&lt;p&gt;React states are a fundamental concept in React programming. They are used to store and manage data that changes over time, such as user input, API responses, or component updates. In this article, we'll explore what React states are, how they work, and how to use them in your React projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are React States?
&lt;/h2&gt;

&lt;p&gt;React states are JavaScript objects that hold information about a component's state. They are used to store and update data that can change over time, such as a component's user interface or its data model. States are essential for building interactive and responsive user interfaces in React, and they allow developers to manage complex application logic with ease.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do React States Work?
&lt;/h2&gt;

&lt;p&gt;When a component's state changes, React automatically re-renders the component and its child components. This ensures that the user interface reflects the current state of the application. States are typically initialized in the component's constructor, and they are updated using the setState method. The setState method is used to update the component's state, and it takes an object as an argument. The object can contain one or more key-value pairs, where the key represents the state property, and the value represents its new value. When setState is called, React updates the component's state and re-renders the component.&lt;/p&gt;

&lt;p&gt;Here's an example of a simple React state:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;jsx&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="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;Component&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="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&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;Counter&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;count&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&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;&lt;/span&gt;&lt;span class="nx"&gt;div&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;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&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;/p&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;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;})}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Increment&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&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="p"&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;In this example, the Counter component has a state property count, which is initialized to 0 in the constructor. The render method displays the current count value, and the onClick event handler updates the count state by calling the setState method.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use React States in Your Projects
&lt;/h2&gt;

&lt;p&gt;To use React states in your projects, you'll need to follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new React component and import the React and Component modules.&lt;/li&gt;
&lt;li&gt;Define the component's state properties in the constructor method.&lt;/li&gt;
&lt;li&gt;Render the component's user interface using the state properties.&lt;/li&gt;
&lt;li&gt;Add event handlers to update the component's state when necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's an example of a more complex React state:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;jsx&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="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;Component&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="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&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;LoginForm&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;rememberMe&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&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="nx"&gt;handleInputChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&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;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&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;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;checkbox&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;checked&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&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;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// Call API to submit form data&lt;/span&gt;
    &lt;span class="nf"&gt;submitLoginForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Handle success response&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;error&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="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&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;&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&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;label&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
            &lt;span class="nx"&gt;type&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="nx"&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;username&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleInputChange&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/label&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;br&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see a working example of React states go over to my &lt;a href="https://github.com/yosileyid/CodeFolio" rel="noopener noreferrer"&gt;"CodeFolio"&lt;/a&gt; repo and browse the react apps folder, in there you will find an app called &lt;a href="https://github.com/yosileyid/CodeFolio/tree/main/apps/tic-tac-toe" rel="noopener noreferrer"&gt;"tic-tac-toe"&lt;/a&gt; which is using react states in a very simple way to run a tic tac toe game. Comment below and let me see what you have been working on, drop by my discord server and lets work on some apps together!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>snippet</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Publishing A Package To NPM</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Thu, 16 Feb 2023 00:50:41 +0000</pubDate>
      <link>https://forem.com/yosileyid/publishing-a-package-to-npm-4bm</link>
      <guid>https://forem.com/yosileyid/publishing-a-package-to-npm-4bm</guid>
      <description>&lt;p&gt;Npm is a popular package manager for Node.js, which provides a vast range of libraries and packages that can be installed and used to enhance your projects. Creating and publishing a package on Npm is a straightforward process, and this guide will walk you through the steps to successfully publish your package on Npm.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Create your package
&lt;/h2&gt;

&lt;p&gt;To begin, create your package using your preferred programming language. Your package should include a package.json file, which contains essential information about your package, such as its name, version, and dependencies. To create a package.json file, run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This command will prompt you to provide all the necessary details about your package. It's essential to ensure that the package name is unique and descriptive to help users find your package.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Add your files to Git
&lt;/h2&gt;

&lt;p&gt;The next step is to add your files to Git. Ensure that your package files are in a Git repository, and you have committed all the changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Create an Npm account
&lt;/h2&gt;

&lt;p&gt;To publish your package, you must first create an Npm account. If you already have an account, skip this step. You can create an account by running the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Publish your package
&lt;/h2&gt;

&lt;p&gt;Once you've created an Npm account, it's time to publish your package. Use the following command to publish your package:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Npm will then prompt you to log in with your Npm credentials. Once you've logged in, Npm will publish your package to the registry. If everything is successful, you should see a success message, indicating that your package has been published.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Manage your package
&lt;/h2&gt;

&lt;p&gt;Congratulations, your package is now published on Npm. You can view your package and manage its details by visiting the Npm registry. You can also update your package by making changes to your package.json file and re-publishing your package using the npm publish command.&lt;/p&gt;

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

&lt;p&gt;Publishing a package on Npm is a simple and straightforward process that anyone can do. By following the steps outlined in this guide, you can publish your package and share it with the community. Remember to keep your package up-to-date and always respond to issues and queries from your users. Good luck and happy publishing! Please leave a comment below and give me your npm account so I can use your packages. Consider stopping by our &lt;a href="https://discord.gg/KpGXAEnVnv" rel="noopener noreferrer"&gt;discord server&lt;/a&gt; and getting to know the team I work with&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Name Your Branches - The Method I Use...</title>
      <dc:creator>Yosi Leyid</dc:creator>
      <pubDate>Mon, 06 Feb 2023 17:11:54 +0000</pubDate>
      <link>https://forem.com/yosileyid/how-to-name-your-branches-the-method-i-use-2cl4</link>
      <guid>https://forem.com/yosileyid/how-to-name-your-branches-the-method-i-use-2cl4</guid>
      <description>&lt;p&gt;A branching strategy is a convention or a set of rules that specify when branches get created. It helps teams and developers by describing the naming guidelines of branches and elaborates on what use the branches should have, and so on. With a lack of appropriate naming conventions, the code maintenance team suffers numerous confusions and complications. Git branching naming convention supports the organic growth of a codebase in a systematic way. It helps in separating the work strategically. Here we will go over the two main categories of Git branches and we will go over them below.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Two Categories of Git branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Regular Branches&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"main"&lt;/li&gt;
&lt;li&gt;"dev"&lt;/li&gt;
&lt;li&gt;"test"&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Temporary Branches&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"fix"&lt;/li&gt;
&lt;li&gt;"wip"&lt;/li&gt;
&lt;li&gt;"bug"&lt;/li&gt;
&lt;li&gt;"feat"&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Regular Branches
&lt;/h2&gt;

&lt;p&gt;Regular branches are branches that are available permanently in the repository, the naming convention of regular branches is easy and straightforward. They are usually named &lt;code&gt;main&lt;/code&gt; when you initialize the repository. If you are going to be making a large project it is a good idea to go ahead and name the other branches for the purposes of development. These are usually named &lt;code&gt;main&lt;/code&gt;, &lt;code&gt;dev&lt;/code&gt;, (&lt;code&gt;test&lt;/code&gt; or &lt;code&gt;qa&lt;/code&gt;), &lt;code&gt;fix&lt;/code&gt;, and &lt;code&gt;feat&lt;/code&gt;. We will go over each of these below and explain their uses.&lt;/p&gt;

&lt;h3&gt;
  
  
  Main
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;main&lt;/code&gt; branch is the default branch available in the Git repository. Team members need to keep the &lt;code&gt;main&lt;/code&gt; branch stable and updated. It usually is stable and doesn't allow direct check-in. Merging is possible only after code review.&lt;/p&gt;

&lt;h3&gt;
  
  
  Development (&lt;code&gt;dev&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;dev&lt;/code&gt;, this is the main development branch, it restricts developers from adding any changes in the master branch directly. Before merging to the master, changes made in the dev branch undergo reviews and tests. Some large companies will require developers to add their name to the branch so they are easily tracked such as &lt;code&gt;yosileyid-dev-audio.plugin&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  QA or test branch
&lt;/h3&gt;

&lt;p&gt;This branch holds the &lt;code&gt;qa&lt;/code&gt; or &lt;code&gt;test&lt;/code&gt; codes and automation testing of the implemented changes. It ensures a stable codebase for the production environment through the testing process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Temporary Git branches
&lt;/h2&gt;

&lt;p&gt;Team members can create and delete these branches whenever it is required. They are not meant to stay in production. If they address the "Issue" then push them upstream to &lt;code&gt;test&lt;/code&gt; and delete the branch. Below are the most common names used for temp branches. There are a large number of recommended conventions and formats, following which could be a challenging task. The best practices of the Git branch naming convention are up to you and your company as to how to best use these. The methods I have used before as detailed below. One of the best methods to improve efficiency is by adding a word that categorizes the branch. &lt;/p&gt;

&lt;p&gt;The general idea is to use short words. The word selection could be anything that suits your working system. With the help of the category word, it is effortless to identify the purpose of the Git branch and attend to it. Prefixes such as; hotfix, feature, chore, or any other variant to categorize a task, increase the work requiring more decision-making while naming. With unique issue tracker IDs, you are essentially marking the task's category in the tracker and adding many useful contexts.&lt;/p&gt;

&lt;h3&gt;
  
  
  WIP
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;wip-{feature.name}&lt;/code&gt;: Work in progress and needs your attention. Developers mostly work on several issues at a given time, and an issue tracker helps to connect the working branch with relevant tasks. It makes tracking team progress very easy.&lt;/p&gt;

&lt;h3&gt;
  
  
  FIX
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;fix-#{bug.number}&lt;/code&gt;: This usually fixes something that broke and doesnt require an entire rewrite of the code base.&lt;/p&gt;

&lt;h3&gt;
  
  
  BUG
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;bug-#{bug.number}&lt;/code&gt;: A bug or an error that needs fixing promptly. Using an external issue tracking ID in the branch name can facilitate tracking the progress from external systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  FEAT
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;feat-name&lt;/code&gt;: A new feature to be implemented. This is usually something to merge into &lt;code&gt;test&lt;/code&gt; as it is added. It will be buggy and require testing from various devices and users before it can be pushed into production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using hyphen or slash separators
&lt;/h3&gt;

&lt;p&gt;The preference between a hyphen, slash, or underscore separator is based on you and your team's choice. The idea is to keep it tightly consistent. Without the separators, the names become more challenging to read, creating confusion for the team. Using separators such as underscores, you can improve the readability and make the name more comfortable to manage. Separators are especially more significant if you are dealing with a vast number of branches. Many companies use the technique of adding the author's name to the branch names such as  (&lt;code&gt;yosileyid-#11457-bug&lt;/code&gt; || &lt;code&gt;yosileyid_#11457_bug&lt;/code&gt;), (&lt;code&gt;yosileyid-#5562-feat&lt;/code&gt; || &lt;code&gt;yosileyid_#5562_feat&lt;/code&gt;) and so on. This method helps to track the work of different developers. With further requirements, progressive additions are also possible. Using only numbers in the branch name's issue ID can lead to more confusion for the team. Such confusion during the merging process of Git branches may lead to a lot of mistakes.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>tooling</category>
      <category>devex</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
