<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://hmz.ie/feed.xml" rel="self" type="application/atom+xml" /><link href="https://hmz.ie/" rel="alternate" type="text/html" /><updated>2026-07-13T19:14:21+00:00</updated><id>https://hmz.ie/feed.xml</id><title type="html">Housam Ziad</title><subtitle>Software Engineer by day, lecturer by night, electronics hobbyist in between — basically a 24/7 nerd on a quest for happyness, one pixel at a time.  I&apos;m also a Peace Commissioner appointed for County Dublin and adjacent counties, providing certification and witnessing services to the public.</subtitle><entry><title type="html">Exploring Essential JavaScript Concepts</title><link href="https://hmz.ie/exploring-essential-javascript-concepts/" rel="alternate" type="text/html" title="Exploring Essential JavaScript Concepts" /><published>2024-07-02T00:00:00+00:00</published><updated>2024-07-02T00:00:00+00:00</updated><id>https://hmz.ie/exploring-essential-javascript-concepts</id><content type="html" xml:base="https://hmz.ie/exploring-essential-javascript-concepts/"><![CDATA[<p>JavaScript is a versatile and powerful programming language that’s essential for web development. Whether you’re building simple web pages or complex applications, understanding core JavaScript concepts can significantly improve your coding efficiency and effectiveness. This blog post will delve into some fundamental JavaScript concepts with detailed explanations and examples.</p>

<h2 id="1-event-loop">1. Event Loop</h2>

<p>The event loop is a crucial concept for understanding how JavaScript handles asynchronous operations. JavaScript is single-threaded, meaning it can execute one piece of code at a time. The event loop allows JavaScript to perform non-blocking operations by offloading tasks to the web APIs and bringing them back to the main thread when they are ready.</p>

<h3 id="example">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">start</span><span class="dl">'</span><span class="p">);</span>

<span class="nx">setTimeout</span><span class="p">(()</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">middle</span><span class="dl">'</span><span class="p">);</span>
<span class="p">},</span> <span class="mi">2000</span><span class="p">);</span>

<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">end</span><span class="dl">'</span><span class="p">);</span>
</code></pre></div></div>

<p><strong>Output:</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>start
end
middle
</code></pre></div></div>

<p>In this example, <code class="language-plaintext highlighter-rouge">setTimeout</code> moves the callback to the web API, which pushes it to the callback queue after 2000ms. The event loop then moves it to the call stack once the main script execution is completed.</p>

<h2 id="2-const-var--let">2. Const, Var &amp; Let</h2>

<p>JavaScript provides three ways to declare variables: <code class="language-plaintext highlighter-rouge">var</code>, <code class="language-plaintext highlighter-rouge">let</code>, and <code class="language-plaintext highlighter-rouge">const</code>.</p>

<ul>
  <li><strong>Var:</strong> Function-scoped or globally scoped if declared outside a function.</li>
  <li><strong>Let:</strong> Block-scoped, allowing you to restrict variables to the block where they are declared.</li>
  <li><strong>Const:</strong> Block-scoped and must be initialized during declaration; it cannot be reassigned.</li>
</ul>

<h3 id="example-1">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">name</span> <span class="o">=</span> <span class="dl">"</span><span class="s2">John</span><span class="dl">"</span><span class="p">;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">name</span><span class="p">);</span> <span class="c1">// John</span>

<span class="kd">let</span> <span class="nx">age</span> <span class="o">=</span> <span class="mi">25</span><span class="p">;</span>
<span class="nx">age</span> <span class="o">=</span> <span class="mi">30</span><span class="p">;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">age</span><span class="p">);</span> <span class="c1">// 30</span>

<span class="kd">const</span> <span class="nx">PI</span> <span class="o">=</span> <span class="mf">3.14</span><span class="p">;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">PI</span><span class="p">);</span> <span class="c1">// 3.14</span>
</code></pre></div></div>

<h2 id="3-functions--scope">3. Functions &amp; Scope</h2>

<p>Functions in JavaScript are first-class citizens, meaning they can be assigned to variables, passed as arguments, and returned from other functions. The scope determines the accessibility of variables within a function or block.</p>

<h3 id="example-2">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">add</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">result</span> <span class="o">=</span> <span class="nx">a</span> <span class="o">+</span> <span class="nx">b</span><span class="p">;</span>
  <span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
<span class="p">}</span>

<span class="kd">const</span> <span class="nx">x</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">multiply</span><span class="p">(</span><span class="nx">y</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">result</span> <span class="o">=</span> <span class="nx">x</span> <span class="o">*</span> <span class="nx">y</span><span class="p">;</span>
  <span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
<span class="p">}</span>

<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">add</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">));</span> <span class="c1">// 5</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">multiply</span><span class="p">(</span><span class="mi">4</span><span class="p">));</span> <span class="c1">// 20</span>
</code></pre></div></div>

<h2 id="4-hoisting">4. Hoisting</h2>

<p>Hoisting is JavaScript’s default behavior of moving declarations to the top of the current scope. It applies to both variable and function declarations.</p>

<h3 id="example-3">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">x</span><span class="p">);</span> <span class="c1">// undefined</span>
<span class="kd">var</span> <span class="nx">x</span> <span class="o">=</span> <span class="mi">5</span><span class="p">;</span>
</code></pre></div></div>

<p>In this example, the declaration <code class="language-plaintext highlighter-rouge">var x</code> is hoisted to the top, but the initialization (<code class="language-plaintext highlighter-rouge">x = 5</code>) is not, leading to <code class="language-plaintext highlighter-rouge">undefined</code>.</p>

<h2 id="5-closures">5. Closures</h2>

<p>Closures allow a function to access variables from its outer scope even after the outer function has executed. This is possible because functions retain access to the scope in which they were created.</p>

<h3 id="example-4">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">outerFunction</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">x</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span>
  <span class="kd">function</span> <span class="nx">innerFunction</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">x</span><span class="p">);</span>
  <span class="p">}</span>
  <span class="k">return</span> <span class="nx">innerFunction</span><span class="p">;</span>
<span class="p">}</span>

<span class="kd">const</span> <span class="nx">newFunction</span> <span class="o">=</span> <span class="nx">outerFunction</span><span class="p">();</span>
<span class="nx">newFunction</span><span class="p">();</span> <span class="c1">// 10</span>
</code></pre></div></div>

<h2 id="6-objects--methods">6. Objects &amp; Methods</h2>

<p>Objects in JavaScript are collections of key-value pairs. Methods are functions defined within an object that can access and manipulate the object’s properties.</p>

<h3 id="example-5">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">person</span> <span class="o">=</span> <span class="p">{</span>
  <span class="na">firstName</span><span class="p">:</span> <span class="dl">"</span><span class="s2">John</span><span class="dl">"</span><span class="p">,</span>
  <span class="na">lastName</span><span class="p">:</span> <span class="dl">"</span><span class="s2">Doe</span><span class="dl">"</span><span class="p">,</span>
  <span class="na">fullName</span><span class="p">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">return</span> <span class="s2">`</span><span class="p">${</span><span class="k">this</span><span class="p">.</span><span class="nx">firstName</span><span class="p">}</span><span class="s2"> </span><span class="p">${</span><span class="k">this</span><span class="p">.</span><span class="nx">lastName</span><span class="p">}</span><span class="s2">`</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">};</span>

<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">person</span><span class="p">.</span><span class="nx">firstName</span><span class="p">);</span> <span class="c1">// John</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">person</span><span class="p">.</span><span class="nx">fullName</span><span class="p">());</span> <span class="c1">// John Doe</span>
</code></pre></div></div>

<h2 id="7-this">7. ‘This’</h2>

<p>The <code class="language-plaintext highlighter-rouge">this</code> keyword refers to the object that is executing the current function. Its value depends on how the function is called.</p>

<h3 id="example-6">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">person</span> <span class="o">=</span> <span class="p">{</span>
  <span class="na">firstName</span><span class="p">:</span> <span class="dl">"</span><span class="s2">John</span><span class="dl">"</span><span class="p">,</span>
  <span class="na">lastName</span><span class="p">:</span> <span class="dl">"</span><span class="s2">Doe</span><span class="dl">"</span><span class="p">,</span>
  <span class="na">fullName</span><span class="p">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">return</span> <span class="s2">`</span><span class="p">${</span><span class="k">this</span><span class="p">.</span><span class="nx">firstName</span><span class="p">}</span><span class="s2"> </span><span class="p">${</span><span class="k">this</span><span class="p">.</span><span class="nx">lastName</span><span class="p">}</span><span class="s2">`</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">};</span>

<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">person</span><span class="p">.</span><span class="nx">fullName</span><span class="p">());</span> <span class="c1">// John Doe</span>
</code></pre></div></div>

<h2 id="8-arrays">8. Arrays</h2>

<p>Arrays are ordered collections of values. JavaScript provides various methods to manipulate arrays.</p>

<h3 id="example-7">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">numbers</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">];</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">numbers</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span> <span class="c1">// 1</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">numbers</span><span class="p">.</span><span class="nx">length</span><span class="p">);</span> <span class="c1">// 5</span>
</code></pre></div></div>

<h2 id="9-map-reduce--filter">9. Map, Reduce &amp; Filter</h2>

<p>These array methods are powerful tools for transforming and reducing arrays.</p>

<ul>
  <li><strong>Map:</strong> Creates a new array by applying a function to each element.</li>
  <li><strong>Reduce:</strong> Reduces the array to a single value by applying a function.</li>
  <li><strong>Filter:</strong> Creates a new array with elements that pass a test.</li>
</ul>

<h3 id="example-8">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">numbers</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">];</span>

<span class="kd">const</span> <span class="nx">squares</span> <span class="o">=</span> <span class="nx">numbers</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">x</span> <span class="o">=&gt;</span> <span class="nx">x</span> <span class="o">*</span> <span class="nx">x</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">squares</span><span class="p">);</span> <span class="c1">// [1, 4, 9, 16, 25]</span>

<span class="kd">const</span> <span class="nx">sum</span> <span class="o">=</span> <span class="nx">numbers</span><span class="p">.</span><span class="nx">reduce</span><span class="p">((</span><span class="nx">total</span><span class="p">,</span> <span class="nx">current</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="nx">total</span> <span class="o">+</span> <span class="nx">current</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">sum</span><span class="p">);</span> <span class="c1">// 15</span>

<span class="kd">const</span> <span class="nx">evenNumbers</span> <span class="o">=</span> <span class="nx">numbers</span><span class="p">.</span><span class="nx">filter</span><span class="p">(</span><span class="nx">x</span> <span class="o">=&gt;</span> <span class="nx">x</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">===</span> <span class="mi">0</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">evenNumbers</span><span class="p">);</span> <span class="c1">// [2, 4]</span>
</code></pre></div></div>

<h2 id="10-async--await">10. Async &amp; Await</h2>

<p>Async and Await are syntactic sugar over Promises, making asynchronous code look and behave more like synchronous code.</p>

<h3 id="example-9">Example:</h3>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">fetchData</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">return</span> <span class="k">new</span> <span class="nb">Promise</span><span class="p">((</span><span class="nx">resolve</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="nx">setTimeout</span><span class="p">(()</span> <span class="o">=&gt;</span> <span class="p">{</span>
      <span class="nx">resolve</span><span class="p">(</span><span class="dl">'</span><span class="s1">Data has been fetched</span><span class="dl">'</span><span class="p">);</span>
    <span class="p">},</span> <span class="mi">2000</span><span class="p">);</span>
  <span class="p">});</span>
<span class="p">}</span>

<span class="k">async</span> <span class="kd">function</span> <span class="nx">printData</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">data</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">fetchData</span><span class="p">();</span>
  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
<span class="p">}</span>

<span class="nx">printData</span><span class="p">();</span>
</code></pre></div></div>

<p><strong>Output:</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Data has been fetched
</code></pre></div></div>

<p>By mastering these concepts, you can write efficient, clean, and maintainable JavaScript code. Each concept builds on the previous ones, creating a robust foundation for your development skills. Happy coding!</p>]]></content><author><name></name></author><category term="Software Engineering" /><category term="development" /><category term="software-engineering" /><category term="javascript" /><summary type="html"><![CDATA[JavaScript is a versatile and powerful programming language that’s essential for web development. Whether you’re building simple web pages or complex applications, understanding core JavaScript concepts can significantly improve your coding efficiency and effectiveness. This blog post will delve into some fundamental JavaScript concepts with detailed explanations and examples.]]></summary></entry><entry><title type="html">Umm Kulthum Encyclopedia - موسوعة أم كلثوم</title><link href="https://hmz.ie/umm-kulthum-encyclopedia/" rel="alternate" type="text/html" title="Umm Kulthum Encyclopedia - موسوعة أم كلثوم" /><published>2024-04-23T00:00:00+00:00</published><updated>2024-04-23T00:00:00+00:00</updated><id>https://hmz.ie/umm-kulthum-encyclopedia</id><content type="html" xml:base="https://hmz.ie/umm-kulthum-encyclopedia/"><![CDATA[<p><img src="https://www.hmz.ie/images/media/2024/umm-kulthum.png" alt="Umm Kulthum" width="600" /></p>

<div class="tabs">
  <input type="radio" name="tabs" id="tabone" checked="checked" />
  <label for="tabone">English</label>
	<div class="tab">
		<p>
			Ever heard of Umm Kulthum? If not, you're in for a treat! This legendary Egyptian singer had a powerful voice and left behind a huge collection of songs that people still love today, even though her career spanned way back from the 1920s to the 1970s.
		</p>
		<p>
			This website <a href="https://umm-kulthum.netlify.app">umm-kulthum.netlify.app</a> explores all the songs Umm Kulthum sang.  Most of her songs talked about love and longing, and the site lists all of them with their titles, who wrote them, and when they came out.
		</p>
  </div>
  
  <input type="radio" name="tabs" id="tabtwo" />
  <label for="tabtwo" class="arabic">عربي</label>
  <div class="tab arabic">
    <h3>موسوعة أم كلثوم</h3>
		<p>
		المطربة المصرية الأسطورية التي تمتعت بصوت قوي وتركت وراءها مجموعة ضخمة من الأغاني التي لا يزال الناس يحبونها حتى اليوم، على الرغم من أن مسيرتها امتدت من العشرينيات إلى السبعينيات.
		</p>
		<p>
		هذا الموقع <a href="https://umm-kulthum.netlify.app">umm-kulthum.netlify.app</a> يستكشف جميع الأغاني التي غنتها أم كلثوم. أغلب أغانيها تحدثت عن الحب والشوق، ويسرد الموقع جميع أغانيها مع الكلمات، والمؤلفين ومتى صدرت.</p>
  </div>
</div>]]></content><author><name></name></author><category term="Music" /><category term="music" /><category term="react" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Declarative vs Procedural Programming</title><link href="https://hmz.ie/declarative-procedural-programming/" rel="alternate" type="text/html" title="Declarative vs Procedural Programming" /><published>2023-02-16T00:00:00+00:00</published><updated>2023-02-16T00:00:00+00:00</updated><id>https://hmz.ie/declarative-procedural-programming</id><content type="html" xml:base="https://hmz.ie/declarative-procedural-programming/"><![CDATA[<p>When it comes to programming, there are two main paradigms: declarative and procedural. Both paradigms have their own unique approach to problem-solving, and it’s important to understand the differences between the two. In this blog post, we’ll explore what declarative and procedural programming are, their characteristics, and how they differ.</p>

<h2 id="what-is-procedural-programming">What is Procedural Programming?</h2>
<p>Procedural programming is a programming paradigm where a program is composed of a series of instructions that tell the computer what to do step-by-step. The focus of procedural programming is on how to accomplish a task or solve a problem using a specific sequence of instructions. The programmer must have a clear understanding of the program’s flow and how each instruction affects the program’s output.</p>

<p>Procedural programming is best suited for situations where the program must have a specific order of execution, such as when working with low-level hardware or optimizing performance. Examples of procedural programming languages include C, Pascal, and FORTRAN.</p>

<h2 id="what-is-declarative-programming">What is Declarative Programming?</h2>
<p>Declarative programming is a programming paradigm that focuses on describing the desired result or outcome rather than how to achieve it. Instead of specifying the sequence of steps to take, declarative programming involves declaring a set of constraints or rules that define what the program should do. The program then uses these rules to automatically generate the output.</p>

<p>Declarative programming is ideal for situations where the focus is on what needs to be done rather than how it should be done. It’s often used for high-level programming, such as artificial intelligence, machine learning, and web development. Examples of declarative programming languages include SQL, HTML, and CSS.</p>

<h2 id="what-are-the-differences-between-declarative-and-procedural-programming">What Are the Differences Between Declarative and Procedural Programming?</h2>
<p>One of the key differences between declarative and procedural programming is the level of abstraction. Procedural programming focuses on the specific steps required to accomplish a task, while declarative programming abstracts away the details of how the task is accomplished.</p>

<p>Another difference is in the order of execution. Procedural programming requires a specific order of execution, while declarative programming can generate the output in any order.</p>

<p>Additionally, declarative programming tends to be more concise and easier to read than procedural programming. Declarative programs are often shorter and more self-explanatory because they focus on the end result rather than the process.</p>

<p>Finally, declarative programming is often more modular and easier to maintain than procedural programming. Because declarative programs focus on what needs to be done rather than how to do it, they can be broken down into smaller, more manageable parts that are easier to maintain and update.</p>

<h2 id="examples">Examples</h2>
<h3 id="declarative-programming">Declarative Programming:</h3>
<ol>
  <li>
    <p>SQL - Structured Query Language is a declarative language used to interact with relational databases. In SQL, you describe the data that you want to retrieve using statements like “SELECT,” “FROM,” and “WHERE,” rather than specifying how the data should be retrieved.</p>
  </li>
  <li>
    <p>HTML - HyperText Markup Language is a declarative language used to create web pages. In HTML, you describe the structure and content of a page using tags, such as “h1” for headings, “p” for paragraphs, and “img” for images.</p>
  </li>
  <li>
    <p>CSS - Cascading Style Sheets is a declarative language used to define the presentation of HTML documents. In CSS, you describe the style and layout of a web page using properties like “font-size,” “background-color,” and “margin.”</p>
  </li>
</ol>

<h3 id="procedural-programming">Procedural Programming:</h3>
<ol>
  <li>
    <p>C - C is a procedural programming language commonly used for low-level programming and systems programming. In C, you write a series of instructions that are executed in a specific order to accomplish a task, such as “if” statements, “for” loops, and “while” loops.</p>
  </li>
  <li>
    <p>Pascal - Pascal is a procedural programming language that was originally designed for teaching programming concepts. In Pascal, you write a sequence of instructions to accomplish a task, using constructs like “if-then-else” statements, “while” loops, and “case” statements.</p>
  </li>
  <li>
    <p>FORTRAN - FORTRAN is a procedural programming language commonly used for scientific and engineering applications. In FORTRAN, you write a sequence of instructions to perform mathematical operations, using constructs like “do” loops and “if” statements.</p>
  </li>
</ol>

<h2 id="conclusion">Conclusion</h2>
<p>Declarative and procedural programming are two different paradigms with their own strengths and weaknesses. While procedural programming is ideal for low-level programming and optimizing performance, declarative programming is ideal for high-level programming and focusing on what needs to be done. Understanding the differences between the two can help you choose the right programming paradigm for your next project.</p>]]></content><author><name></name></author><category term="Software Engineering" /><category term="development" /><category term="software-engineering" /><summary type="html"><![CDATA[When it comes to programming, there are two main paradigms: declarative and procedural. Both paradigms have their own unique approach to problem-solving, and it’s important to understand the differences between the two. In this blog post, we’ll explore what declarative and procedural programming are, their characteristics, and how they differ.]]></summary></entry><entry><title type="html">Introduction to React Testing Library</title><link href="https://hmz.ie/intro-to-react-testing-library/" rel="alternate" type="text/html" title="Introduction to React Testing Library" /><published>2023-01-10T00:00:00+00:00</published><updated>2023-01-10T00:00:00+00:00</updated><id>https://hmz.ie/intro-to-react-testing-library</id><content type="html" xml:base="https://hmz.ie/intro-to-react-testing-library/"><![CDATA[<p>React is one of the most popular front-end libraries used for building web applications. It offers a lot of features, including virtual DOM, component-based architecture, and unidirectional data flow. However, testing React applications can be a bit challenging because of the dynamic nature of the library.</p>

<p>React Testing Library is a library that helps in testing React applications by focusing on what the user sees and does, instead of testing the implementation details of the application. In this blog post, we will explore the React Testing Library and how it can be used to test React applications.</p>

<h2 id="setting-up-react-testing-library">Setting up React Testing Library</h2>

<p>To use the React Testing Library, we need to install it first. We can do this by running the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npm <span class="nb">install</span> <span class="nt">--save-dev</span> @testing-library/react
</code></pre></div></div>

<p>This will install the React Testing Library as a development dependency in our project. We can then import the library in our test files like this:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">render</span><span class="p">,</span> <span class="nx">screen</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">@testing-library/react</span><span class="dl">"</span><span class="p">;</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">render</code> function is used to render a React component and returns a container object that we can use to interact with the rendered component. The <code class="language-plaintext highlighter-rouge">screen</code> object provides various functions that allow us to find elements in the rendered component.</p>

<h2 id="writing-tests-using-react-testing-library">Writing tests using React Testing Library</h2>

<h3 id="testing-a-simple-react-component">Testing a simple React component</h3>

<p>Let’s say we have a simple React component that displays a button and a message. We want to test that clicking the button updates the message correctly. Here is the code for the component:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">React</span><span class="p">,</span> <span class="p">{</span> <span class="nx">useState</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">MyComponent</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">message</span><span class="p">,</span> <span class="nx">setMessage</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">(</span><span class="dl">"</span><span class="s2">Initial message</span><span class="dl">"</span><span class="p">);</span>

  <span class="kd">function</span> <span class="nx">handleClick</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">setMessage</span><span class="p">(</span><span class="dl">"</span><span class="s2">New message</span><span class="dl">"</span><span class="p">);</span>
  <span class="p">}</span>

  <span class="k">return</span> <span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">button</span> <span class="nx">onClick</span><span class="o">=</span><span class="p">{</span><span class="nx">handleClick</span><span class="p">}</span><span class="o">&gt;</span><span class="nx">Click</span> <span class="nx">me</span><span class="o">&lt;</span><span class="sr">/button</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="p">{</span><span class="nx">message</span><span class="p">}</span><span class="o">&lt;</span><span class="sr">/p</span><span class="err">&gt;
</span>    <span class="o">&lt;</span><span class="sr">/div</span><span class="err">&gt;
</span>  <span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>To test this component using React Testing Library, we can create a test file and write the following test:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">render</span><span class="p">,</span> <span class="nx">screen</span><span class="p">,</span> <span class="nx">fireEvent</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">@testing-library/react</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">MyComponent</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./MyComponent</span><span class="dl">"</span><span class="p">;</span>

<span class="nx">test</span><span class="p">(</span><span class="dl">"</span><span class="s2">updates message on button click</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">render</span><span class="p">(</span><span class="o">&lt;</span><span class="nx">MyComponent</span> <span class="o">/&gt;</span><span class="p">);</span>
  <span class="kd">const</span> <span class="nx">button</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByText</span><span class="p">(</span><span class="dl">"</span><span class="s2">Click me</span><span class="dl">"</span><span class="p">);</span>
  <span class="nx">fireEvent</span><span class="p">.</span><span class="nx">click</span><span class="p">(</span><span class="nx">button</span><span class="p">);</span>
  <span class="kd">const</span> <span class="nx">message</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByText</span><span class="p">(</span><span class="dl">"</span><span class="s2">New message</span><span class="dl">"</span><span class="p">);</span>
  <span class="nx">expect</span><span class="p">(</span><span class="nx">message</span><span class="p">).</span><span class="nx">toBeInTheDocument</span><span class="p">();</span>
<span class="p">});</span>
</code></pre></div></div>

<p>In this test, we use the <code class="language-plaintext highlighter-rouge">render</code> function to render the <code class="language-plaintext highlighter-rouge">MyComponent</code> component. We then use the <code class="language-plaintext highlighter-rouge">screen</code> object to find the button element by its text and simulate a click event using the <code class="language-plaintext highlighter-rouge">fireEvent</code> function. Finally, we use the <code class="language-plaintext highlighter-rouge">screen</code> object again to find the message element by its text and assert that it is in the document using the <code class="language-plaintext highlighter-rouge">toBeInTheDocument</code> function.</p>

<h3 id="testing-a-form-submission">Testing a Form Submission</h3>

<p>Let’s say we have a simple React component that displays a form with an input field and a submit button. We want to test that filling out the form and submitting it calls the appropriate function with the input value. Here is the code for the component:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">React</span><span class="p">,</span> <span class="p">{</span> <span class="nx">useState</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">MyForm</span><span class="p">({</span> <span class="nx">onSubmit</span> <span class="p">})</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">inputValue</span><span class="p">,</span> <span class="nx">setInputValue</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">(</span><span class="dl">""</span><span class="p">);</span>

  <span class="kd">function</span> <span class="nx">handleSubmit</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">event</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span>
    <span class="nx">onSubmit</span><span class="p">(</span><span class="nx">inputValue</span><span class="p">);</span>
  <span class="p">}</span>

  <span class="k">return</span> <span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">form</span> <span class="nx">onSubmit</span><span class="o">=</span><span class="p">{</span><span class="nx">handleSubmit</span><span class="p">}</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">label</span><span class="o">&gt;</span>
        <span class="nx">Input</span> <span class="nx">value</span><span class="p">:</span>
        <span class="o">&lt;</span><span class="nx">input</span>
          <span class="nx">value</span><span class="o">=</span><span class="p">{</span><span class="nx">inputValue</span><span class="p">}</span>
          <span class="nx">onChange</span><span class="o">=</span><span class="p">{(</span><span class="nx">event</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="nx">setInputValue</span><span class="p">(</span><span class="nx">event</span><span class="p">.</span><span class="nx">target</span><span class="p">.</span><span class="nx">value</span><span class="p">)}</span>
        <span class="sr">/</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="sr">/label</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="nx">button</span> <span class="nx">type</span><span class="o">=</span><span class="dl">"</span><span class="s2">submit</span><span class="dl">"</span><span class="o">&gt;</span><span class="nx">Submit</span><span class="o">&lt;</span><span class="sr">/button</span><span class="err">&gt;
</span>    <span class="o">&lt;</span><span class="sr">/form</span><span class="err">&gt;
</span>  <span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>To test this component using React Testing Library, we can create a test file and write the following test:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">render</span><span class="p">,</span> <span class="nx">screen</span><span class="p">,</span> <span class="nx">fireEvent</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">@testing-library/react</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">MyForm</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./MyForm</span><span class="dl">"</span><span class="p">;</span>

<span class="nx">test</span><span class="p">(</span><span class="dl">"</span><span class="s2">calls onSubmit with input value on form submit</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">mockSubmit</span> <span class="o">=</span> <span class="nx">jest</span><span class="p">.</span><span class="nx">fn</span><span class="p">();</span>
  <span class="nx">render</span><span class="p">(</span><span class="o">&lt;</span><span class="nx">MyForm</span> <span class="nx">onSubmit</span><span class="o">=</span><span class="p">{</span><span class="nx">mockSubmit</span><span class="p">}</span> <span class="sr">/&gt;</span><span class="se">)</span><span class="err">;
</span>  <span class="kd">const</span> <span class="nx">input</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByLabelText</span><span class="p">(</span><span class="dl">"</span><span class="s2">Input value:</span><span class="dl">"</span><span class="p">);</span>
  <span class="kd">const</span> <span class="nx">submitButton</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByText</span><span class="p">(</span><span class="dl">"</span><span class="s2">Submit</span><span class="dl">"</span><span class="p">);</span>
  <span class="nx">fireEvent</span><span class="p">.</span><span class="nx">change</span><span class="p">(</span><span class="nx">input</span><span class="p">,</span> <span class="p">{</span> <span class="na">target</span><span class="p">:</span> <span class="p">{</span> <span class="na">value</span><span class="p">:</span> <span class="dl">"</span><span class="s2">test value</span><span class="dl">"</span> <span class="p">}</span> <span class="p">});</span>
  <span class="nx">fireEvent</span><span class="p">.</span><span class="nx">click</span><span class="p">(</span><span class="nx">submitButton</span><span class="p">);</span>
  <span class="nx">expect</span><span class="p">(</span><span class="nx">mockSubmit</span><span class="p">).</span><span class="nx">toHaveBeenCalledWith</span><span class="p">(</span><span class="dl">"</span><span class="s2">test value</span><span class="dl">"</span><span class="p">);</span>
<span class="p">});</span>
</code></pre></div></div>

<p>In this test, we use the <code class="language-plaintext highlighter-rouge">render</code> function to render the <code class="language-plaintext highlighter-rouge">MyForm</code> component with a mock <code class="language-plaintext highlighter-rouge">onSubmit</code> function. We then use the <code class="language-plaintext highlighter-rouge">screen</code> object to find the input and submit button elements by their text and label. We simulate a change event on the input field to set its value to “test value”, and then we simulate a click event on the submit button. Finally, we use the <code class="language-plaintext highlighter-rouge">toHaveBeenCalledWith</code> function to assert that the <code class="language-plaintext highlighter-rouge">onSubmit</code> function was called with the input value.</p>

<h3 id="testing-a-component-that-uses-a-custom-hook">Testing a Component that Uses a Custom Hook</h3>

<p>Let’s say we have a React component that uses a custom hook to fetch some data from an API and display it. We want to test that the component displays the data correctly when the hook returns it. Here is the code for the component and the custom hook:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">React</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">useData</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./useData</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">MyComponent</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">{</span> <span class="nx">isLoading</span><span class="p">,</span> <span class="nx">data</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">useData</span><span class="p">();</span>

  <span class="k">if</span> <span class="p">(</span><span class="nx">isLoading</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">Loading</span><span class="p">...</span><span class="o">&lt;</span><span class="sr">/p&gt;</span><span class="err">;
</span>  <span class="p">}</span>

  <span class="k">return</span> <span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span>
      <span class="p">{</span><span class="nx">data</span><span class="p">.</span><span class="nx">map</span><span class="p">((</span><span class="nx">item</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">(</span>
        <span class="o">&lt;</span><span class="nx">p</span> <span class="nx">key</span><span class="o">=</span><span class="p">{</span><span class="nx">item</span><span class="p">.</span><span class="nx">id</span><span class="p">}</span><span class="o">&gt;</span><span class="p">{</span><span class="nx">item</span><span class="p">.</span><span class="nx">name</span><span class="p">}</span><span class="o">&lt;</span><span class="sr">/p</span><span class="err">&gt;
</span>      <span class="p">))}</span>
    <span class="o">&lt;</span><span class="sr">/div</span><span class="err">&gt;
</span>  <span class="p">);</span>
<span class="p">}</span>

<span class="k">export</span> <span class="k">default</span> <span class="nx">MyComponent</span><span class="p">;</span>
</code></pre></div></div>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">useState</span><span class="p">,</span> <span class="nx">useEffect</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">useData</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">isLoading</span><span class="p">,</span> <span class="nx">setIsLoading</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">data</span><span class="p">,</span> <span class="nx">setData</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="p">([]);</span>

  <span class="nx">useEffect</span><span class="p">(()</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="nx">fetch</span><span class="p">(</span><span class="dl">"</span><span class="s2">https://my-api.com/data</span><span class="dl">"</span><span class="p">)</span>
      <span class="p">.</span><span class="nx">then</span><span class="p">((</span><span class="nx">response</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="nx">response</span><span class="p">.</span><span class="nx">json</span><span class="p">())</span>
      <span class="p">.</span><span class="nx">then</span><span class="p">((</span><span class="nx">data</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>
        <span class="nx">setData</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
        <span class="nx">setIsLoading</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span>
      <span class="p">});</span>
  <span class="p">},</span> <span class="p">[]);</span>

  <span class="k">return</span> <span class="p">{</span> <span class="nx">isLoading</span><span class="p">,</span> <span class="nx">data</span> <span class="p">};</span>
<span class="p">}</span>

<span class="k">export</span> <span class="k">default</span> <span class="nx">useData</span><span class="p">;</span>
</code></pre></div></div>

<p>To test this component using React Testing Library, we can create a test file and write the following test:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">render</span><span class="p">,</span> <span class="nx">screen</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">@testing-library/react</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">useData</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./useData</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">MyComponent</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./MyComponent</span><span class="dl">"</span><span class="p">;</span>

<span class="nx">jest</span><span class="p">.</span><span class="nx">mock</span><span class="p">(</span><span class="dl">"</span><span class="s2">./useData</span><span class="dl">"</span><span class="p">);</span>

<span class="nx">test</span><span class="p">(</span><span class="dl">"</span><span class="s2">displays data when loaded</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">useData</span><span class="p">.</span><span class="nx">mockReturnValue</span><span class="p">({</span>
    <span class="na">isLoading</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span>
    <span class="na">data</span><span class="p">:</span> <span class="p">[</span>
      <span class="p">{</span> <span class="na">id</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="na">name</span><span class="p">:</span> <span class="dl">"</span><span class="s2">Item 1</span><span class="dl">"</span> <span class="p">},</span>
      <span class="p">{</span> <span class="na">id</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="na">name</span><span class="p">:</span> <span class="dl">"</span><span class="s2">Item 2</span><span class="dl">"</span> <span class="p">},</span>
    <span class="p">],</span>
  <span class="p">});</span>
  <span class="nx">render</span><span class="p">(</span><span class="o">&lt;</span><span class="nx">MyComponent</span> <span class="o">/&gt;</span><span class="p">);</span>
  <span class="kd">const</span> <span class="nx">item1</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByText</span><span class="p">(</span><span class="dl">"</span><span class="s2">Item 1</span><span class="dl">"</span><span class="p">);</span>
  <span class="kd">const</span> <span class="nx">item2</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByText</span><span class="p">(</span><span class="dl">"</span><span class="s2">Item 2</span><span class="dl">"</span><span class="p">);</span>
  <span class="nx">expect</span><span class="p">(</span><span class="nx">item1</span><span class="p">).</span><span class="nx">toBeInTheDocument</span><span class="p">();</span>
  <span class="nx">expect</span><span class="p">(</span><span class="nx">item2</span><span class="p">).</span><span class="nx">toBeInTheDocument</span><span class="p">();</span>
<span class="p">});</span>
</code></pre></div></div>

<p>In this test, we use the <code class="language-plaintext highlighter-rouge">jest.mock</code> function to mock the <code class="language-plaintext highlighter-rouge">useData</code> hook and return some sample data. We then use the <code class="language-plaintext highlighter-rouge">render</code> function to render the <code class="language-plaintext highlighter-rouge">MyComponent</code> component, and we use the <code class="language-plaintext highlighter-rouge">screen</code> object to find the elements that should contain the data. Finally, we use the <code class="language-plaintext highlighter-rouge">toBeInTheDocument</code> function to assert that the elements are present in the document.</p>

<h3 id="testing-a-component-that-uses-react-router">Testing a Component that Uses React Router</h3>

<p>Let’s say we have a React component that uses React Router to display different content based on the URL. We want to test that the component renders the correct content for each URL. Here is the code for the component:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">React</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">Switch</span><span class="p">,</span> <span class="nx">Route</span><span class="p">,</span> <span class="nx">Link</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react-router-dom</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">MyRouter</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">return</span> <span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">nav</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="nx">ul</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="nx">li</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="nx">Link</span> <span class="nx">to</span><span class="o">=</span><span class="dl">"</span><span class="s2">/</span><span class="dl">"</span><span class="o">&gt;</span><span class="nx">Home</span><span class="o">&lt;</span><span class="sr">/Link</span><span class="err">&gt;
</span>          <span class="o">&lt;</span><span class="sr">/li</span><span class="err">&gt;
</span>          <span class="o">&lt;</span><span class="nx">li</span><span class="o">&gt;</span>
            <span class="o">&lt;</span><span class="nx">Link</span> <span class="nx">to</span><span class="o">=</span><span class="dl">"</span><span class="s2">/about</span><span class="dl">"</span><span class="o">&gt;</span><span class="nx">About</span><span class="o">&lt;</span><span class="sr">/Link</span><span class="err">&gt;
</span>          <span class="o">&lt;</span><span class="sr">/li</span><span class="err">&gt;
</span>        <span class="o">&lt;</span><span class="sr">/ul</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="sr">/nav</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="nx">Switch</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="nx">Route</span> <span class="nx">path</span><span class="o">=</span><span class="dl">"</span><span class="s2">/about</span><span class="dl">"</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">About</span> <span class="nx">content</span><span class="o">&lt;</span><span class="sr">/p</span><span class="err">&gt;
</span>        <span class="o">&lt;</span><span class="sr">/Route</span><span class="err">&gt;
</span>        <span class="o">&lt;</span><span class="nx">Route</span> <span class="nx">path</span><span class="o">=</span><span class="dl">"</span><span class="s2">/</span><span class="dl">"</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">Home</span> <span class="nx">content</span><span class="o">&lt;</span><span class="sr">/p</span><span class="err">&gt;
</span>        <span class="o">&lt;</span><span class="sr">/Route</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="sr">/Switch</span><span class="err">&gt;
</span>    <span class="o">&lt;</span><span class="sr">/div</span><span class="err">&gt;
</span>  <span class="p">);</span>
<span class="p">}</span>

<span class="k">export</span> <span class="k">default</span> <span class="nx">MyRouter</span><span class="p">;</span>
</code></pre></div></div>

<p>To test this component using React Testing Library, we can create a test file and write the following test:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">render</span><span class="p">,</span> <span class="nx">screen</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">@testing-library/react</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">MemoryRouter</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react-router-dom</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">MyRouter</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./MyRouter</span><span class="dl">"</span><span class="p">;</span>

<span class="nx">test</span><span class="p">(</span><span class="dl">"</span><span class="s2">renders home content for the home URL</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">render</span><span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">MemoryRouter</span> <span class="nx">initialEntries</span><span class="o">=</span><span class="p">{[</span><span class="dl">"</span><span class="s2">/</span><span class="dl">"</span><span class="p">]}</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">MyRouter</span> <span class="o">/&gt;</span>
    <span class="o">&lt;</span><span class="sr">/MemoryRouter</span><span class="err">&gt;
</span>  <span class="p">);</span>
  <span class="kd">const</span> <span class="nx">homeContent</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByText</span><span class="p">(</span><span class="dl">"</span><span class="s2">Home content</span><span class="dl">"</span><span class="p">);</span>
  <span class="nx">expect</span><span class="p">(</span><span class="nx">homeContent</span><span class="p">).</span><span class="nx">toBeInTheDocument</span><span class="p">();</span>
<span class="p">});</span>

<span class="nx">test</span><span class="p">(</span><span class="dl">"</span><span class="s2">renders about content for the about URL</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">render</span><span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">MemoryRouter</span> <span class="nx">initialEntries</span><span class="o">=</span><span class="p">{[</span><span class="dl">"</span><span class="s2">/about</span><span class="dl">"</span><span class="p">]}</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">MyRouter</span> <span class="o">/&gt;</span>
    <span class="o">&lt;</span><span class="sr">/MemoryRouter</span><span class="err">&gt;
</span>  <span class="p">);</span>
  <span class="kd">const</span> <span class="nx">aboutContent</span> <span class="o">=</span> <span class="nx">screen</span><span class="p">.</span><span class="nx">getByText</span><span class="p">(</span><span class="dl">"</span><span class="s2">About content</span><span class="dl">"</span><span class="p">);</span>
  <span class="nx">expect</span><span class="p">(</span><span class="nx">aboutContent</span><span class="p">).</span><span class="nx">toBeInTheDocument</span><span class="p">();</span>
<span class="p">});</span>
</code></pre></div></div>

<p>In these tests, we use the <code class="language-plaintext highlighter-rouge">MemoryRouter</code> component from React Router to simulate different URLs. We use the <code class="language-plaintext highlighter-rouge">initialEntries</code> prop to set the initial URL to either “/” or “/about”. We then use the <code class="language-plaintext highlighter-rouge">render</code> function to render the <code class="language-plaintext highlighter-rouge">MyRouter</code> component inside the <code class="language-plaintext highlighter-rouge">MemoryRouter</code>. Finally, we use the <code class="language-plaintext highlighter-rouge">screen</code> object to find the elements that should contain the content for each URL, and we use the <code class="language-plaintext highlighter-rouge">toBeInTheDocument</code> function to assert that the elements are present in the document.</p>

<h2 id="conclusion">Conclusion</h2>

<p>React Testing Library is a powerful tool that can help us test React applications more efficiently. By focusing on the user’s perspective, we can write tests that are more resilient to changes in the implementation details of our application. We can use the library to test various aspects of our application, including user interactions, state changes, and component rendering. With the examples above, you can get started with React Testing Library and start writing efficient tests for your React applications.</p>]]></content><author><name></name></author><category term="Development" /><category term="development" /><category term="react" /><category term="software-testing" /><summary type="html"><![CDATA[React is one of the most popular front-end libraries used for building web applications. It offers a lot of features, including virtual DOM, component-based architecture, and unidirectional data flow. However, testing React applications can be a bit challenging because of the dynamic nature of the library.]]></summary></entry><entry><title type="html">How To Add Multiple Pages in React (2023 Tutorial)</title><link href="https://hmz.ie/add-multiple-pages-react/" rel="alternate" type="text/html" title="How To Add Multiple Pages in React (2023 Tutorial)" /><published>2023-01-06T00:00:00+00:00</published><updated>2023-01-06T00:00:00+00:00</updated><id>https://hmz.ie/add-multiple-pages-react</id><content type="html" xml:base="https://hmz.ie/add-multiple-pages-react/"><![CDATA[<p>React is a popular JavaScript library used for building web applications. One of the essential features of a web application is the ability to navigate between different pages. In this tutorial, we will explore how to add multiple pages in a React application.</p>

<p>First, let’s create a new React application using the Create React App command-line tool. Open your terminal and run the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npx create-react-app my-app
</code></pre></div></div>

<p>This will create a new React application in the “my-app” directory.</p>

<p>Next, we need to install React Router, which is a popular library used for client-side routing. Open your terminal and run the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npm <span class="nb">install </span>react-router-dom
</code></pre></div></div>

<p>Once the installation is complete, we can start creating multiple pages in our React application.</p>

<h2 id="create-a-new-component-for-each-page">Create a New Component for Each Page</h2>
<p>The first step is to create a new component for each page in your application. Each component will represent a different page that the user can navigate to. For example, if you’re building a blog, you might have a component for the homepage, a component for a single blog post, and a component for an about page.</p>

<p>Here’s an example of what a basic page component might look like:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">React</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">HomePage</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">return</span> <span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">h1</span><span class="o">&gt;</span><span class="nx">Welcome</span> <span class="nx">to</span> <span class="nx">my</span> <span class="nx">website</span><span class="o">&lt;</span><span class="sr">/h1</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="nx">p</span><span class="o">&gt;</span><span class="nx">Here</span><span class="dl">'</span><span class="s1">s some content for the homepage&lt;/p&gt;
    &lt;/div&gt;
  );
}

export default HomePage;
</span></code></pre></div></div>

<p>This component represents the homepage of your application. You can create additional components for each page in the same way.</p>

<h2 id="set-up-routes">Set Up Routes</h2>
<p>Now that we have our page components, we need to set up routes so that the user can navigate to each page. Open the “App.js” file and import the necessary components:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">React</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">BrowserRouter</span> <span class="k">as</span> <span class="nx">Router</span><span class="p">,</span> <span class="nx">Switch</span><span class="p">,</span> <span class="nx">Route</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react-router-dom</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">HomePage</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./HomePage</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">AboutPage</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./AboutPage</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">BlogPostPage</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./BlogPostPage</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">App</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">return</span> <span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">Router</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="nx">Switch</span><span class="o">&gt;</span>
          <span class="o">&lt;</span><span class="nx">Route</span> <span class="nx">exact</span> <span class="nx">path</span><span class="o">=</span><span class="dl">"</span><span class="s2">/</span><span class="dl">"</span> <span class="nx">component</span><span class="o">=</span><span class="p">{</span><span class="nx">HomePage</span><span class="p">}</span> <span class="sr">/</span><span class="err">&gt;
</span>          <span class="o">&lt;</span><span class="nx">Route</span> <span class="nx">path</span><span class="o">=</span><span class="dl">"</span><span class="s2">/about</span><span class="dl">"</span> <span class="nx">component</span><span class="o">=</span><span class="p">{</span><span class="nx">AboutPage</span><span class="p">}</span> <span class="sr">/</span><span class="err">&gt;
</span>          <span class="o">&lt;</span><span class="nx">Route</span> <span class="nx">path</span><span class="o">=</span><span class="dl">"</span><span class="s2">/blog/:id</span><span class="dl">"</span> <span class="nx">component</span><span class="o">=</span><span class="p">{</span><span class="nx">BlogPostPage</span><span class="p">}</span> <span class="sr">/</span><span class="err">&gt;
</span>        <span class="o">&lt;</span><span class="sr">/Switch</span><span class="err">&gt;
</span>      <span class="o">&lt;</span><span class="sr">/div</span><span class="err">&gt;
</span>    <span class="o">&lt;</span><span class="sr">/Router</span><span class="err">&gt;
</span>  <span class="p">);</span>
<span class="p">}</span>

<span class="k">export</span> <span class="k">default</span> <span class="nx">App</span><span class="p">;</span>
</code></pre></div></div>

<p>In this example, we have set up routes for three different pages: the homepage, the about page, and a blog post page. The “exact” keyword is used to indicate that the path must match exactly for the homepage route.</p>

<p>We use the “Switch” component to ensure that only one route is matched at a time. The “Route” component is used to define each route and its corresponding component.</p>

<p>Add Navigation Links</p>

<p>Now that we have our routes set up, we need to add navigation links to our application. We can do this by using the “Link” component provided by React Router.</p>

<p>Here’s an example of what the navigation links might look like:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">React</span> <span class="k">from</span> <span class="dl">'</span><span class="s1">react</span><span class="dl">'</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">Link</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">'</span><span class="s1">react-router-dom</span><span class="dl">'</span><span class="p">;</span>

<span class="kd">function</span> <span class="nx">Navigation</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">return</span> <span class="p">(</span>
    <span class="o">&lt;</span><span class="nx">nav</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="nx">ul</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="nx">li</span><span class="o">&gt;&lt;</span><span class="nx">Link</span> <span class="nx">to</span><span class="o">=</span><span class="dl">"</span><span class="s2">/</span><span class="dl">"</span><span class="o">&gt;</span><span class="nx">Home</span><span class="o">&lt;</span><span class="sr">/Link&gt;&lt;/</span><span class="nx">li</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="nx">li</span><span class="o">&gt;&lt;</span><span class="nx">Link</span> <span class="nx">to</span><span class="o">=</span><span class="dl">"</span><span class="s2">/about</span><span class="dl">"</span><span class="o">&gt;</span><span class="nx">About</span><span class="o">&lt;</span><span class="sr">/Link&gt;&lt;/</span><span class="nx">li</span><span class="o">&gt;</span>
      <span class="o">&lt;</span><span class="sr">/ul</span><span class="err">&gt;
</span>    <span class="o">&lt;</span><span class="sr">/nav</span><span class="err">&gt;
</span>  <span class="p">);</span>
<span class="p">}</span>

<span class="k">export</span> <span class="k">default</span> <span class="nx">Navigation</span><span class="p">;</span>
</code></pre></div></div>

<p>This component creates a navigation bar with links to the homepage and about page.</p>

<h2 id="conclusion">Conclusion</h2>
<p>In this tutorial, we have learned how to add multiple pages in a React application using React Router. We created a new component for each page, set up routes using the “Route” component, and added navigation links using the “Link” component provided by React Router. Now that you have a basic understanding of how to add multiple pages in a React application, you can start building more complex web applications with multiple pages and routes.</p>

<p>There are many other features and options available in React Router, such as passing parameters in the URL, redirecting to a different page, and using nested routes. The React Router documentation provides a detailed guide on how to use these features.</p>

<p>In addition to React Router, there are other libraries and tools available for client-side routing in React applications, such as Reach Router and Next.js. Each library has its own set of features and benefits, so it’s important to research and choose the one that best fits your needs.</p>

<p>In conclusion, adding multiple pages in a React application is an essential part of building a web application. By following the steps outlined in this tutorial, you can start building web applications with multiple pages and routes. With the help of React Router and other libraries, you can create complex and interactive web applications that provide a seamless user experience.</p>]]></content><author><name></name></author><category term="Development" /><category term="development" /><category term="react" /><summary type="html"><![CDATA[React is a popular JavaScript library used for building web applications. One of the essential features of a web application is the ability to navigate between different pages. In this tutorial, we will explore how to add multiple pages in a React application.]]></summary></entry><entry><title type="html">Software Engineering Career Paths [Regulary Updated]</title><link href="https://hmz.ie/software-engineering-career/" rel="alternate" type="text/html" title="Software Engineering Career Paths [Regulary Updated]" /><published>2023-01-01T00:00:00+00:00</published><updated>2023-01-01T00:00:00+00:00</updated><id>https://hmz.ie/software-engineering-career</id><content type="html" xml:base="https://hmz.ie/software-engineering-career/"><![CDATA[<p>As a software engineer, there are a wide variety of career paths available to you. Whether you prefer to code all day, work on project management, or delve into emerging technologies, there is a job out there for you. In this blog post, we’ll explore some of the most popular career paths for software engineers.</p>

<h2 id="career-paths">Career Paths</h2>
<h3 id="software-developerprogrammer">Software Developer/Programmer</h3>
<p>Software development or programming is the most traditional and common career path for software engineers. As a software developer or programmer, you will design, write, test, and maintain code for software applications. Depending on your specialty, you may work on front-end or back-end development, web applications, mobile apps, desktop software, or other types of software.</p>

<p>Software development is a highly diverse field with many different specializations. Within the field, there are a variety of career paths for software engineers, each with its own unique set of skills and requirements. Let’s take a closer look at some of the most popular career paths in software development.</p>

<h4 id="front-end-development">Front-end Development</h4>
<p>Front-end developers are responsible for designing and implementing the user interface and user experience of web applications. They work with HTML, CSS, and JavaScript to create dynamic and responsive web pages. Front-end developers need to have a strong understanding of user experience design and a good eye for aesthetics. They also need to be proficient in various front-end frameworks and libraries like React, Angular, and Vue.js.</p>

<p>Career paths for front-end developers include UI/UX designers, front-end engineers, web developers, and user experience designers.</p>

<h4 id="back-end-development">Back-end Development</h4>
<p>Back-end developers work on the server-side of web applications, creating the infrastructure that supports the front-end. They are responsible for building and maintaining servers, databases, and APIs. Back-end developers work with programming languages like Java, Python, Ruby, and PHP. They also need to have a strong understanding of databases and server infrastructure.</p>

<p>Career paths for back-end developers include software developers, back-end engineers, database administrators, and DevOps engineers.</p>

<h4 id="web-applications">Web Applications</h4>
<p>Web application developers work on web-based software applications that run on the internet. They build both front-end and back-end components and are responsible for ensuring that the application is reliable, efficient, and secure. Web application developers work with a range of programming languages and frameworks, depending on the requirements of the project.</p>

<p>Career paths for web application developers include web developers, full-stack developers, front-end developers, and back-end developers.</p>

<h4 id="mobile-apps">Mobile Apps</h4>
<p>Mobile app developers create software applications that run on mobile devices like smartphones and tablets. They work with mobile operating systems like iOS and Android and are responsible for building both front-end and back-end components of the application. Mobile app developers need to be proficient in programming languages like Java, Swift, and Kotlin.</p>

<p>Career paths for mobile app developers include mobile developers, mobile software engineers, and mobile application architects.</p>

<h4 id="desktop-software">Desktop Software</h4>
<p>Desktop software developers create software applications that run on desktop computers. They work with operating systems like Windows, macOS, and Linux and are responsible for building both front-end and back-end components of the application. Desktop software developers need to be proficient in programming languages like Java, C++, and Python.</p>

<p>Career paths for desktop software developers include software developers, desktop software engineers, and desktop application architects.</p>

<h3 id="devops-engineer">DevOps Engineer</h3>
<p>DevOps engineers work to integrate and streamline the processes between software development and IT operations. They are responsible for automating processes and tools to improve efficiency, quality, and security. DevOps engineers need to be proficient in programming, scripting, and automation tools, as well as be familiar with system administration and deployment processes.</p>

<h3 id="data-scientist">Data Scientist</h3>
<p>Data science is a rapidly growing field, and software engineers are well-positioned to excel in it. Data scientists analyze and interpret large data sets to identify patterns and trends, and they use this information to help businesses make data-driven decisions. As a data scientist, you’ll need to be skilled in programming, data analysis, statistics, and machine learning.</p>

<h3 id="project-manager">Project Manager</h3>
<p>Project management is a leadership role that involves managing teams, budgets, timelines, and resources to ensure successful completion of projects. As a software engineer, you have a unique perspective on the technical aspects of software development, which can be incredibly valuable when managing software projects.</p>

<h3 id="cybersecurity-specialist">Cybersecurity Specialist</h3>
<p>In today’s digital age, cybersecurity is more important than ever. Cybersecurity specialists work to protect organizations from digital threats and vulnerabilities by implementing security measures and protocols, as well as identifying and mitigating security risks. As a cybersecurity specialist, you’ll need to be familiar with programming, network security, cryptography, and other security-related technologies.</p>

<h3 id="technical-writer">Technical Writer</h3>
<p>Technical writing is an excellent career path for software engineers who enjoy writing and communicating technical information to others. Technical writers create documentation, manuals, guides, and other materials that explain how to use software products, as well as the technical aspects of software development. This role requires strong writing skills, as well as knowledge of software development tools and processes.</p>

<h3 id="uxui-designer">UX/UI Designer</h3>
<p>User experience (UX) and user interface (UI) designers work to create intuitive, user-friendly interfaces for software products. As a software engineer, you have a unique understanding of the technical aspects of software development, which can be valuable when designing interfaces that are both visually appealing and functional. UX/UI designers need to be proficient in design tools, as well as have a strong understanding of user psychology and behavior.</p>

<h2 id="is-software-engineering-the-correct-career-for-you">Is Software Engineering the correct career for you?</h2>
<p>Choosing a career can be a challenging decision, and it’s important to make an informed decision. Here are some steps you can take to determine if software engineering is the correct career for you:</p>

<ol>
  <li>
    <p>Understand the role: Before committing to a career in software engineering, it’s essential to understand the role and the responsibilities involved. You can talk to software engineers or read online to understand what the job entails and what skills are required.</p>
  </li>
  <li>
    <p>Take a programming course: If you are new to software engineering, you can take a programming course to see if you enjoy programming. Online courses like Codecademy, Coursera, or Udacity offer free programming courses that can give you an idea of what software engineering is all about.</p>
  </li>
  <li>
    <p>Build a project: Building a simple software project can give you a good idea of what it’s like to work on a software development project. You can build a simple web application or mobile app and see if you enjoy the process of designing and developing software.</p>
  </li>
  <li>
    <p>Attend a software engineering event: Attending a software engineering event or conference can give you an opportunity to network with other software engineers and gain a deeper understanding of the field.</p>
  </li>
  <li>
    <p>Consider your interests and strengths: If you are considering a career in software engineering, it’s important to consider your interests and strengths. If you enjoy solving complex problems, have strong analytical skills, and enjoy working with technology, then software engineering may be a good fit for you.</p>
  </li>
  <li>
    <p>Research career prospects: Research the job market and career prospects in software engineering. Look at the job outlook, salary, and career growth opportunities to determine if it’s the right fit for you.</p>
  </li>
</ol>

<h2 id="skills-needed-for-a-software-engineer">Skills needed for a Software Engineer</h2>
<p>A software engineer is responsible for designing, developing, testing, and maintaining software applications. To be successful in this field, software engineers need to have a range of technical and soft skills. Here are some of the key skills needed for a software engineer:</p>

<ol>
  <li>
    <p>Programming languages: Software engineers need to be proficient in at least one programming language. Common programming languages include Java, Python, C++, JavaScript, and Ruby.</p>
  </li>
  <li>
    <p>Data structures and algorithms: Software engineers need to have a good understanding of data structures and algorithms. They need to be able to write efficient and optimized code.</p>
  </li>
  <li>
    <p>Web development: Software engineers working on web applications need to have a good understanding of web development technologies like HTML, CSS, and JavaScript. They should also be familiar with front-end frameworks like React, Angular, and Vue.js.</p>
  </li>
  <li>
    <p>Database management: Software engineers should be familiar with databases and data modeling. They should be able to design and manage databases efficiently.</p>
  </li>
  <li>
    <p>Testing and debugging: Software engineers need to be skilled in testing and debugging software applications. They should be able to write unit tests, integration tests, and end-to-end tests.</p>
  </li>
  <li>
    <p>Version control: Software engineers should be familiar with version control systems like Git. They should be able to work collaboratively with other developers and manage code changes efficiently.</p>
  </li>
  <li>
    <p>Problem-solving skills: Software engineers need to be excellent problem solvers. They should be able to identify problems and come up with creative and efficient solutions.</p>
  </li>
  <li>
    <p>Communication skills: Software engineers need to have good communication skills. They should be able to explain technical concepts to non-technical stakeholders and work collaboratively with other team members.</p>
  </li>
  <li>
    <p>Continuous learning: Software engineering is a fast-changing field. Software engineers need to be dedicated to continuous learning and staying up-to-date with the latest trends and technologies.</p>
  </li>
</ol>

<h2 id="starting-a-career-as-a-software-engineer">Starting a career as a Software Engineer</h2>
<p>Starting a career as a software engineer can be a rewarding and lucrative career choice. Here are some steps to help you get started:</p>

<ol>
  <li>
    <p>Learn programming fundamentals: Start by learning programming fundamentals like data types, variables, control structures, and algorithms. You can begin by learning a popular programming language like Python, Java, or JavaScript. You can take online courses, watch videos, or read books to learn programming.</p>
  </li>
  <li>
    <p>Build a strong foundation: Once you have learned the basics of programming, focus on building a strong foundation in computer science. You can learn about data structures, algorithms, computer organization, operating systems, and networking. A strong foundation in computer science will help you understand how software works at a deeper level.</p>
  </li>
  <li>
    <p>Practice coding: Practice coding regularly by working on projects or solving coding challenges. You can contribute to open source projects or build your own projects. Coding is a skill that requires practice, so the more you code, the better you will become.</p>
  </li>
  <li>
    <p>Get a degree or certification: You can choose to pursue a degree in computer science or a related field to get a formal education in software engineering. Alternatively, you can pursue a certification in a specific technology or programming language to demonstrate your expertise.</p>
  </li>
  <li>
    <p>Build a portfolio: Build a portfolio of your projects to showcase your skills and experience. Your portfolio can include projects you have worked on, open-source contributions, and any certifications or degrees you have earned.</p>
  </li>
  <li>
    <p>Find internships or entry-level jobs: Look for internships or entry-level jobs to gain experience and build your network. Internships or entry-level jobs can help you learn from experienced professionals and provide you with valuable industry experience.</p>
  </li>
  <li>
    <p>Keep learning and networking: Keep up with the latest trends and technologies in software engineering. Attend meetups, conferences, and events to network with other professionals in the field.</p>
  </li>
</ol>

<h2 id="interviews">Interviews</h2>
<p>The interview process for software engineering positions can vary depending on the company and the specific role, but here is a general overview of what you might expect:</p>

<ol>
  <li>
    <p>Phone or initial screening: Many companies start with a brief phone call or screening to discuss your background and experience and to determine if you are a good fit for the position.</p>
  </li>
  <li>
    <p>Technical assessment: After the initial screening, you may be asked to complete a technical assessment or coding challenge to demonstrate your technical skills and abilities.</p>
  </li>
  <li>
    <p>Technical interview: A technical interview will typically follow the assessment, and you may be asked to answer technical questions, solve problems, or write code on a whiteboard or in a code editor. The interviewer may also ask you to explain your thought process or approach to solving a problem.</p>
  </li>
  <li>
    <p>Behavioral or cultural fit interview: In addition to assessing your technical skills, companies may also evaluate your cultural fit and soft skills. You may be asked about your communication style, your approach to teamwork, your problem-solving process, and your approach to personal and professional development.</p>
  </li>
  <li>
    <p>Onsite or virtual interviews: If you have passed the initial interviews, you may be invited to an onsite or virtual interview with a team or groups of people you will be working with. During this interview, you may be asked to give a technical presentation, work on a collaborative coding exercise, or meet with different members of the team.</p>
  </li>
  <li>
    <p>Offer: If you successfully make it through the interview process, you may be presented with a job offer.</p>
  </li>
</ol>

<p>It’s important to remember that the interview process may differ from company to company and that some companies may have more or fewer steps than those outlined above. Additionally, some companies may conduct interviews over several days or weeks. Being prepared and having a good understanding of the company’s interview process can help you feel more confident and comfortable during the interview process.</p>

<h3 id="faq-in-interviews">FAQ in interviews</h3>
<p>As a software engineer, here are some frequently asked questions (FAQ) that you may encounter in interviews:</p>

<ol>
  <li>What programming languages are you proficient in?</li>
  <li>Have you worked on any projects similar to what we are looking for?</li>
  <li>Can you explain a complex technical concept in simple terms?</li>
  <li>How do you stay up-to-date with the latest technologies and trends?</li>
  <li>What is your experience with version control systems?</li>
  <li>Can you walk us through your development process?</li>
  <li>How do you approach problem-solving?</li>
  <li>How do you ensure code quality and maintainability?</li>
  <li>Can you give an example of a difficult bug you had to debug and how you went about solving it?</li>
  <li>How do you work in a team environment and collaborate with other developers, designers, and stakeholders?</li>
</ol>

<p>In conclusion, software engineering offers a wealth of career opportunities. From traditional software development roles to emerging fields like data science and cybersecurity, there is a job out there for every type of software engineer. Whether you prefer to code all day, manage projects, or design user interfaces, the world of software engineering is full of exciting and fulfilling career paths.<br />
Software engineering is a highly technical and challenging field that requires a range of technical and soft skills. Successful software engineers are skilled in programming languages, data structures, web development, database management, testing and debugging, version control, problem-solving, communication, and continuous learning.<br />
Starting a career as a software engineer requires dedication, hard work, and continuous learning. With the right skills and experience, you can find a rewarding career in software engineering.</p>]]></content><author><name></name></author><category term="Software Engineering" /><category term="development" /><category term="software-engineering" /><category term="career" /><summary type="html"><![CDATA[As a software engineer, there are a wide variety of career paths available to you. Whether you prefer to code all day, work on project management, or delve into emerging technologies, there is a job out there for you. In this blog post, we’ll explore some of the most popular career paths for software engineers.]]></summary></entry><entry><title type="html">How to Create a Python Virtual Environment on Ubuntu 22.10</title><link href="https://hmz.ie/python-virtual-environment-ubuntu2210/" rel="alternate" type="text/html" title="How to Create a Python Virtual Environment on Ubuntu 22.10" /><published>2022-12-01T00:00:00+00:00</published><updated>2022-12-01T00:00:00+00:00</updated><id>https://hmz.ie/python-virtual-environment-ubuntu2210</id><content type="html" xml:base="https://hmz.ie/python-virtual-environment-ubuntu2210/"><![CDATA[<p>Python virtual environments allow you to isolate your Python environment and dependencies from your system’s global environment. This is especially useful when working on multiple Python projects that require different versions of packages. In this tutorial, we’ll walk through how to create a Python virtual environment on Ubuntu 22.10.</p>

<h3 id="step-1-install-python">Step 1: Install Python</h3>

<p>Ubuntu 22.10 comes with Python pre-installed, but you may want to make sure you have the latest version installed. To check your version of Python, run the following command in your terminal:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>python3 <span class="nt">--version</span>
</code></pre></div></div>
<p>If you need to install Python, run the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get update
<span class="nb">sudo </span>apt-get <span class="nb">install </span>python3
</code></pre></div></div>
<h3 id="step-2-install-virtualenv">Step 2: Install Virtualenv</h3>

<p>To create a Python virtual environment, we’ll need to install Virtualenv. Run the following command to install Virtualenv:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get <span class="nb">install </span>virtualenv
</code></pre></div></div>
<h3 id="step-3-create-a-virtual-environment">Step 3: Create a Virtual Environment</h3>

<p>Now that we have Virtualenv installed, let’s create a new virtual environment for our project. First, navigate to your project directory:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> /path/to/your/project
Next, create a new virtual environment:
</code></pre></div></div>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>virtualenv venv
</code></pre></div></div>
<p>This will create a new directory called venv in your project directory. This directory will contain a new, isolated Python environment.</p>

<h3 id="step-4-activate-the-virtual-environment">Step 4: Activate the Virtual Environment</h3>

<p>To activate the virtual environment, run the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">source </span>venv/bin/activate
</code></pre></div></div>
<p>You should now see the name of your virtual environment in your terminal prompt.</p>

<h3 id="step-5-install-packages">Step 5: Install Packages</h3>

<p>Now that your virtual environment is activated, you can install packages using pip, just like you would in your global environment. For example:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pip <span class="nb">install </span>numpy
</code></pre></div></div>
<h3 id="step-6-deactivate-the-virtual-environment">Step 6: Deactivate the Virtual Environment</h3>

<p>When you’re finished working in your virtual environment, you can deactivate it by running the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>deactivate
</code></pre></div></div>
<p>This will return you to your global environment.</p>

<p>In this tutorial, we learned how to create a Python virtual environment on Ubuntu 22.10 using Virtualenv. Virtual environments are a powerful tool for managing dependencies and isolating your Python environment. With this knowledge, you can create and work on multiple Python projects with ease.</p>]]></content><author><name></name></author><category term="Tools" /><category term="python" /><category term="ubuntu" /><summary type="html"><![CDATA[Python virtual environments allow you to isolate your Python environment and dependencies from your system’s global environment. This is especially useful when working on multiple Python projects that require different versions of packages. In this tutorial, we’ll walk through how to create a Python virtual environment on Ubuntu 22.10.]]></summary></entry><entry><title type="html">Install PHP on macOS 12.0 Monterey</title><link href="https://hmz.ie/install-php-on-monterey/" rel="alternate" type="text/html" title="Install PHP on macOS 12.0 Monterey" /><published>2022-11-10T00:00:00+00:00</published><updated>2022-11-10T00:00:00+00:00</updated><id>https://hmz.ie/install-php-on-monterey</id><content type="html" xml:base="https://hmz.ie/install-php-on-monterey/"><![CDATA[<p>If you got a new Mac with the latest OS, and you need to develop some PHP projects, you may be surprised that it doesn’t work out-of-the-box any more.<br />
This mean that you need to install and enable it manually.<br />
This guide post will help you setup PHP and get it to run on Apache inside your Mac machine.</p>

<p>PHP is NOT included in Monterey. Apple even included a note about it in <code class="language-plaintext highlighter-rouge">/etc/apache2/httpd.conf</code> saying:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#PHP was deprecated in macOS 11 and removed from macOS 12
</code></pre></div></div>

<p>To Install PHP and get Apache to run on macOS 12, follow these steps:</p>
<ul>
  <li>Start by installing Homebrew if you don’t have it already
<code class="language-plaintext highlighter-rouge">ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</code></li>
  <li>Install PHP by using <code class="language-plaintext highlighter-rouge">brew install php</code><br />
After brew finishes installing, it shows the following message:</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>To enable PHP in Apache add the following to httpd.conf and restart Apache:
  LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

  &lt;FilesMatch \.php$&gt;
    SetHandler application/x-httpd-php
  &lt;/FilesMatch&gt;

Finally, check DirectoryIndex includes index.php
  DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
  /opt/homebrew/etc/php/8.1/
</code></pre></div></div>
<ul>
  <li>Using Homebrew, install the following libraries:</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>brew install openssl
brew install httpd
</code></pre></div></div>
<ul>
  <li>Edit httpd.conf, you can find it on: <code class="language-plaintext highlighter-rouge">/opt/homebrew/etc/httpd/httpd.conf</code></li>
  <li>If you are using nano, scroll to the end by pressing CTRL + W and then CTRL + V and add the following to the conf file</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

&lt;FilesMatch \.php$&gt;
  SetHandler application/x-httpd-php
&lt;/FilesMatch&gt;
</code></pre></div></div>
<ul>
  <li>Search, by using CTRL + W for the following and change them:<br />
<code class="language-plaintext highlighter-rouge">Listen 8080</code> change it to be 80 so you don’t need to specify port every time.</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>DocumentRoot "/Users/your_user/Sites"
&lt;Directory "/Users/your_user/Sites"&gt;
</code></pre></div></div>

<p>change <code class="language-plaintext highlighter-rouge">"/Users/your_user/Sites"</code> to the directory that want to use as your document root.</p>

<ul>
  <li>Restart PHP and Apache</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>brew services restart php
sudo apachectl restart
</code></pre></div></div>
<ul>
  <li>Start httpd</li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>brew services start httpd
</code></pre></div></div>
<ul>
  <li>Put an HTML or PHP file in your document root.</li>
  <li>In your wbe browser, visit <code class="language-plaintext highlighter-rouge">http://localhost</code> and check if you get the code running.</li>
</ul>]]></content><author><name></name></author><category term="Development" /><category term="development" /><category term="php" /><category term="macOS" /><category term="apache" /><summary type="html"><![CDATA[If you got a new Mac with the latest OS, and you need to develop some PHP projects, you may be surprised that it doesn’t work out-of-the-box any more. This mean that you need to install and enable it manually. This guide post will help you setup PHP and get it to run on Apache inside your Mac machine.]]></summary></entry><entry><title type="html">What Does &amp;lt; T &amp;gt; Mean in TypeScript?</title><link href="https://hmz.ie/understanding-t-in-typescript/" rel="alternate" type="text/html" title="What Does &amp;lt; T &amp;gt; Mean in TypeScript?" /><published>2022-11-03T00:00:00+00:00</published><updated>2022-11-03T00:00:00+00:00</updated><id>https://hmz.ie/understanding-t-in-typescript</id><content type="html" xml:base="https://hmz.ie/understanding-t-in-typescript/"><![CDATA[<p>Constructing components with well-defined and consistent APIs that are reusable is a crucial aspect of software engineering. The most flexible approach for creating large software systems involves developing components that can process not only current data but also data that may be introduced in the future.</p>

<p>In programming languages such as C# and Java, a fundamental technique for producing reusable components is the use of generics. Generics make it possible to create a component that can work with multiple types instead of only one. By doing so, users are free to utilize their own types when using these components.</p>

<p>The <code class="language-plaintext highlighter-rouge">&lt;T&gt;</code> syntax in TypeScript represents a type parameter, which allows you to define a generic type that can be used with different types.</p>

<p>In TypeScript, you can define a function, class, or interface that takes one or more type parameters by enclosing them in angle brackets <code class="language-plaintext highlighter-rouge">&lt; &gt;</code>. For example, consider the following function:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">reverse</span><span class="o">&lt;</span><span class="nx">T</span><span class="o">&gt;</span><span class="p">(</span><span class="nx">items</span><span class="p">:</span> <span class="nx">T</span><span class="p">[]):</span> <span class="nx">T</span><span class="p">[]</span> <span class="p">{</span>
  <span class="k">return</span> <span class="nx">items</span><span class="p">.</span><span class="nx">reverse</span><span class="p">();</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Here, the <code class="language-plaintext highlighter-rouge">reverse</code> function takes an array of items of type <code class="language-plaintext highlighter-rouge">T</code>, and returns a reversed array of items of the same type. The <code class="language-plaintext highlighter-rouge">&lt;T&gt;</code> syntax indicates that <code class="language-plaintext highlighter-rouge">T</code> is a type parameter that can be replaced with any actual type when the function is called. For instance, you could call the function with an array of numbers like this:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">numbers</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">];</span>
<span class="kd">const</span> <span class="nx">reversedNumbers</span> <span class="o">=</span> <span class="nx">reverse</span><span class="p">(</span><span class="nx">numbers</span><span class="p">);</span>
</code></pre></div></div>

<p>In this case, the type parameter <code class="language-plaintext highlighter-rouge">T</code> would be inferred as <code class="language-plaintext highlighter-rouge">number</code>, and the <code class="language-plaintext highlighter-rouge">reverse</code> function would return an array of type <code class="language-plaintext highlighter-rouge">number[]</code>.</p>

<p>Type parameters can be useful when you want to write code that is reusable with different types, without having to write separate functions or classes for each type. They allow you to write generic code that works with any type that meets certain constraints.</p>]]></content><author><name></name></author><category term="Development" /><category term="development" /><category term="TypeScript" /><summary type="html"><![CDATA[Constructing components with well-defined and consistent APIs that are reusable is a crucial aspect of software engineering. The most flexible approach for creating large software systems involves developing components that can process not only current data but also data that may be introduced in the future.]]></summary></entry><entry><title type="html">How to code a simple calculator</title><link href="https://hmz.ie/simple-calculator-for-kids/" rel="alternate" type="text/html" title="How to code a simple calculator" /><published>2022-10-18T00:00:00+00:00</published><updated>2022-10-18T00:00:00+00:00</updated><id>https://hmz.ie/simple-calculator-for-kids</id><content type="html" xml:base="https://hmz.ie/simple-calculator-for-kids/"><![CDATA[<p>Hello, everyone! Have you ever used a calculator before? It’s a tool that helps you do math problems quickly and easily. You can use a calculator to add numbers together, subtract them, multiply them, and divide them.</p>

<p>Today, we’re going to learn how to build our very own calculator using a programming language called <code class="language-plaintext highlighter-rouge">JavaScript</code>, a web page language called <code class="language-plaintext highlighter-rouge">HTML</code>, and a styling language called <code class="language-plaintext highlighter-rouge">CSS</code>.</p>

<p>HTML is like a skeleton or a structure for your web page. It’s like the frame of a house. It tells the web browser what to put on the page, like buttons, text, and images.</p>

<p>JavaScript is like the brain of the web page. It’s like a robot that can do things for you. In this case, it can add, subtract, multiply, and divide numbers for you when you press the buttons on the page.</p>

<p>CSS is like the clothes or the decoration for your web page. It’s like the paint and wallpaper that make a house look nice. It tells the web browser how to make things look, like changing the color of the buttons or the font of the text.</p>

<p>So, in the example we created, the HTML code tells the web browser to create a calculator with buttons for numbers and operations. The JavaScript code tells the web browser how to perform calculations when you click the buttons. And the CSS code tells the web browser how to make the calculator look nicer.</p>

<p>Does that make sense to you?</p>

<p>First, let’s start with the HTML. HTML is a language that helps us create the structure and content of a web page. Here’s what the HTML code for our calculator looks like:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">&lt;!DOCTYPE html&gt;</span>
<span class="nt">&lt;html&gt;</span>
  <span class="nt">&lt;head&gt;</span>
    <span class="nt">&lt;title&gt;</span>Simple Calculator<span class="nt">&lt;/title&gt;</span>
    <span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"calculator.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
  <span class="nt">&lt;/head&gt;</span>
  <span class="nt">&lt;body&gt;</span>
    <span class="nt">&lt;h1&gt;</span>Simple Calculator<span class="nt">&lt;/h1&gt;</span>
    <span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">"text"</span> <span class="na">id=</span><span class="s">"result"</span> <span class="na">disabled</span> <span class="nt">/&gt;&lt;br</span> <span class="nt">/&gt;&lt;br</span> <span class="nt">/&gt;</span>

    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"clearResult()"</span><span class="nt">&gt;</span>C<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"deleteDigit()"</span><span class="nt">&gt;</span>Del<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addOperator('%')"</span><span class="nt">&gt;</span>%<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addOperator('/')"</span><span class="nt">&gt;</span>/<span class="nt">&lt;/button&gt;&lt;br</span> <span class="nt">/&gt;</span>

    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(7)"</span><span class="nt">&gt;</span>7<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(8)"</span><span class="nt">&gt;</span>8<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(9)"</span><span class="nt">&gt;</span>9<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addOperator('*')"</span><span class="nt">&gt;</span>*<span class="nt">&lt;/button&gt;&lt;br</span> <span class="nt">/&gt;</span>

    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(4)"</span><span class="nt">&gt;</span>4<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(5)"</span><span class="nt">&gt;</span>5<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(6)"</span><span class="nt">&gt;</span>6<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addOperator('-')"</span><span class="nt">&gt;</span>-<span class="nt">&lt;/button&gt;&lt;br</span> <span class="nt">/&gt;</span>

    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(1)"</span><span class="nt">&gt;</span>1<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(2)"</span><span class="nt">&gt;</span>2<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(3)"</span><span class="nt">&gt;</span>3<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addOperator('+')"</span><span class="nt">&gt;</span>+<span class="nt">&lt;/button&gt;&lt;br</span> <span class="nt">/&gt;</span>

    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDigit(0)"</span><span class="nt">&gt;</span>0<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"addDecimal()"</span><span class="nt">&gt;</span>.<span class="nt">&lt;/button&gt;</span>
    <span class="nt">&lt;button</span> <span class="na">onclick=</span><span class="s">"calculate()"</span><span class="nt">&gt;</span>=<span class="nt">&lt;/button&gt;</span>
  <span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>

<p>As you can see, the HTML code is a list of elements like headings, buttons, and input fields. We use the <code class="language-plaintext highlighter-rouge">&lt;input&gt;</code> tag to create a field that will display the result of our calculations. We also use the <code class="language-plaintext highlighter-rouge">&lt;button&gt;</code> tag to create buttons that we can click on to add numbers and operators to our calculations.</p>

<p>Now, let’s move on to the JavaScript. JavaScript is a programming language that helps us make our web pages interactive. Here’s the JavaScript code for our calculator:</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// These variables store the operator and the previous and current numbers.</span>
<span class="kd">let</span> <span class="nx">operator</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
<span class="kd">let</span> <span class="nx">prevNum</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
<span class="kd">let</span> <span class="nx">currNum</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>

<span class="c1">// This function adds a digit to the current number and displays it in the result field.</span>
<span class="kd">function</span> <span class="nx">addDigit</span><span class="p">(</span><span class="nx">num</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">currNum</span> <span class="o">+=</span> <span class="nx">num</span><span class="p">;</span>
  <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">result</span><span class="dl">"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">currNum</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">// This function adds a decimal point to the current number if it doesn't already contain one.</span>
<span class="kd">function</span> <span class="nx">addDecimal</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">currNum</span><span class="p">.</span><span class="nx">includes</span><span class="p">(</span><span class="dl">"</span><span class="s2">.</span><span class="dl">"</span><span class="p">))</span> <span class="p">{</span>
    <span class="nx">currNum</span> <span class="o">+=</span> <span class="dl">"</span><span class="s2">.</span><span class="dl">"</span><span class="p">;</span>
    <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">result</span><span class="dl">"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">currNum</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>

<span class="c1">// This function adds the given operator to the calculation and calls the calculate function if there is already an operator.</span>
<span class="kd">function</span> <span class="nx">addOperator</span><span class="p">(</span><span class="nx">op</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">operator</span> <span class="o">!==</span> <span class="dl">""</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">calculate</span><span class="p">();</span>
  <span class="p">}</span>
  <span class="nx">operator</span> <span class="o">=</span> <span class="nx">op</span><span class="p">;</span>
  <span class="nx">prevNum</span> <span class="o">=</span> <span class="nx">currNum</span><span class="p">;</span>
  <span class="nx">currNum</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">// This function calculates the result of the expression based on the operator and previous and current numbers.</span>
<span class="kd">function</span> <span class="nx">calculate</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">let</span> <span class="nx">result</span><span class="p">;</span>
  <span class="kd">const</span> <span class="nx">prev</span> <span class="o">=</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">prevNum</span><span class="p">);</span>
  <span class="kd">const</span> <span class="nx">curr</span> <span class="o">=</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">currNum</span><span class="p">);</span>
  <span class="k">if</span> <span class="p">(</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">prev</span><span class="p">)</span> <span class="o">||</span> <span class="nb">isNaN</span><span class="p">(</span><span class="nx">curr</span><span class="p">))</span> <span class="p">{</span>
    <span class="k">return</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="k">switch</span> <span class="p">(</span><span class="nx">operator</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">case</span> <span class="dl">"</span><span class="s2">+</span><span class="dl">"</span><span class="p">:</span>
      <span class="nx">result</span> <span class="o">=</span> <span class="nx">prev</span> <span class="o">+</span> <span class="nx">curr</span><span class="p">;</span>
      <span class="k">break</span><span class="p">;</span>
    <span class="k">case</span> <span class="dl">"</span><span class="s2">-</span><span class="dl">"</span><span class="p">:</span>
      <span class="nx">result</span> <span class="o">=</span> <span class="nx">prev</span> <span class="o">-</span> <span class="nx">curr</span><span class="p">;</span>
      <span class="k">break</span><span class="p">;</span>
    <span class="k">case</span> <span class="dl">"</span><span class="s2">*</span><span class="dl">"</span><span class="p">:</span>
      <span class="nx">result</span> <span class="o">=</span> <span class="nx">prev</span> <span class="o">*</span> <span class="nx">curr</span><span class="p">;</span>
      <span class="k">break</span><span class="p">;</span>
    <span class="k">case</span> <span class="dl">"</span><span class="s2">/</span><span class="dl">"</span><span class="p">:</span>
      <span class="nx">result</span> <span class="o">=</span> <span class="nx">prev</span> <span class="o">/</span> <span class="nx">curr</span><span class="p">;</span>
      <span class="k">break</span><span class="p">;</span>
    <span class="k">case</span> <span class="dl">"</span><span class="s2">%</span><span class="dl">"</span><span class="p">:</span>
      <span class="nx">result</span> <span class="o">=</span> <span class="p">(</span><span class="nx">prev</span> <span class="o">/</span> <span class="mi">100</span><span class="p">)</span> <span class="o">*</span> <span class="nx">curr</span><span class="p">;</span>
      <span class="k">break</span><span class="p">;</span>
    <span class="nl">default</span><span class="p">:</span>
      <span class="k">return</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="nx">operator</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
  <span class="nx">prevNum</span> <span class="o">=</span> <span class="nx">result</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span>
  <span class="nx">currNum</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
  <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">result</span><span class="dl">"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">result</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">// This function clears the operator and previous and current numbers, and clears the result field.</span>
<span class="kd">function</span> <span class="nx">clearResult</span><span class="p">()</span> <span class="p">{</span>
  <span class="nx">operator</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
  <span class="nx">prevNum</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
  <span class="nx">currNum</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
  <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">result</span><span class="dl">"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="dl">""</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">// This function deletes the last digit from the current number and updates the result field.</span>
<span class="kd">function</span> <span class="nx">deleteDigit</span><span class="p">()</span> <span class="p">{</span>
  <span class="nx">currNum</span> <span class="o">=</span> <span class="nx">currNum</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">);</span>
  <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="dl">"</span><span class="s2">result</span><span class="dl">"</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">currNum</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Now to make our calculator look more beautiful, we use a bit of CSS as below:</p>
<div class="language-css highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">body</span> <span class="p">{</span>
  <span class="nl">font-family</span><span class="p">:</span> <span class="n">Arial</span><span class="p">,</span> <span class="nb">sans-serif</span><span class="p">;</span>
  <span class="nl">align-items</span><span class="p">:</span> <span class="nb">center</span><span class="p">;</span>
  <span class="nl">display</span><span class="p">:</span> <span class="n">flex</span><span class="p">;</span>
  <span class="nl">height</span><span class="p">:</span> <span class="m">100vh</span><span class="p">;</span>
  <span class="nl">justify-content</span><span class="p">:</span> <span class="nb">center</span><span class="p">;</span>
<span class="p">}</span>

<span class="nt">h2</span> <span class="p">{</span>
  <span class="nl">text-align</span><span class="p">:</span> <span class="nb">center</span><span class="p">;</span>
<span class="p">}</span>

<span class="nf">#result</span> <span class="p">{</span>
  <span class="nl">display</span><span class="p">:</span> <span class="nb">block</span><span class="p">;</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">215px</span><span class="p">;</span>
  <span class="nl">height</span><span class="p">:</span> <span class="m">50px</span><span class="p">;</span>
  <span class="nl">font-size</span><span class="p">:</span> <span class="m">24px</span><span class="p">;</span>
  <span class="nl">text-align</span><span class="p">:</span> <span class="nb">right</span><span class="p">;</span>
  <span class="nl">padding-right</span><span class="p">:</span> <span class="m">10px</span><span class="p">;</span>
  <span class="nl">margin-bottom</span><span class="p">:</span> <span class="m">10px</span><span class="p">;</span>
<span class="p">}</span>

<span class="nt">button</span> <span class="p">{</span>
  <span class="nl">cursor</span><span class="p">:</span> <span class="nb">pointer</span><span class="p">;</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">50px</span><span class="p">;</span>
  <span class="nl">height</span><span class="p">:</span> <span class="m">50px</span><span class="p">;</span>
  <span class="nl">font-size</span><span class="p">:</span> <span class="m">24px</span><span class="p">;</span>
  <span class="nl">border-radius</span><span class="p">:</span> <span class="m">5px</span><span class="p">;</span>
  <span class="nl">border</span><span class="p">:</span> <span class="nb">none</span><span class="p">;</span>
  <span class="nl">background-color</span><span class="p">:</span> <span class="m">#f5f5f5</span><span class="p">;</span>
  <span class="nl">margin-right</span><span class="p">:</span> <span class="m">5px</span><span class="p">;</span>
  <span class="nl">margin-bottom</span><span class="p">:</span> <span class="m">5px</span><span class="p">;</span>
<span class="p">}</span>

<span class="nt">button</span><span class="nd">:hover</span> <span class="p">{</span>
  <span class="nl">background-color</span><span class="p">:</span> <span class="m">#e0e0e0</span><span class="p">;</span>
<span class="p">}</span>

<span class="nt">button</span><span class="nd">:active</span> <span class="p">{</span>
  <span class="nl">background-color</span><span class="p">:</span> <span class="m">#d0d0d0</span><span class="p">;</span>
<span class="p">}</span>

<span class="nf">#zero</span> <span class="p">{</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">110px</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>You can see the code and the result on a website called CodePen where I put an example.</p>

<iframe height="600" style="width: 100%;" scrolling="no" title="Simple Calculator" src="https://codepen.io/housamz/embed/XWPbKNw?default-tab=html%2Cresult" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
  See the Pen <a href="https://codepen.io/housamz/pen/XWPbKNw">
  Simple Calculator</a> by Housamz (<a href="https://codepen.io/housamz">@housamz</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe>]]></content><author><name></name></author><category term="Development" /><category term="kids-coding" /><category term="development" /><category term="web" /><summary type="html"><![CDATA[Hello, everyone! Have you ever used a calculator before? It’s a tool that helps you do math problems quickly and easily. You can use a calculator to add numbers together, subtract them, multiply them, and divide them.]]></summary></entry></feed>