<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Patrick Akhamiogu on Medium]]></title>
        <description><![CDATA[Stories by Patrick Akhamiogu on Medium]]></description>
        <link>https://medium.com/@patrickakhamiogu?source=rss-5d997d6b1dd9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Z-JnI3_-FrGh_icXA73M4w.jpeg</url>
            <title>Stories by Patrick Akhamiogu on Medium</title>
            <link>https://medium.com/@patrickakhamiogu?source=rss-5d997d6b1dd9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 15 May 2026 15:51:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@patrickakhamiogu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Similarities Between Javascript, Typescript, and C#]]></title>
            <link>https://medium.com/@patrickakhamiogu/similarities-between-javascript-typescript-and-c-df29a46e7b8d?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/df29a46e7b8d</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[c-programming]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Tue, 28 May 2024 20:55:44 GMT</pubDate>
            <atom:updated>2024-05-30T10:21:50.538Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*joZc9bRDtWks6-bx" /><figcaption>Photo by <a href="https://unsplash.com/@nateggrant?utm_source=medium&amp;utm_medium=referral">Nate Grant</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Back then when I started learning programming, I used to wonder how some people know different programming languages and pick them up so fast. But over the years, after mastering and knowing to a large extent how JavaScript works under the hood, I proceeded to learn Typescript, C, and C# (I have done a bit of Python and Java but we are not talking about that today). I started to realize that these programming languages are similar to some extent and I would like to point out some key observations today.</p><p>It might interest you to know that these programming Languages are similar in syntax. They are all members of the C family of languages.</p><p>We would discuss these similarities under the following subheading:<br>1. Object Oriented Programming Language<br>2. Typed Language<br>3. Syntax<br>4. Function Hierarchies<br>5. Package Manager</p><h4>Object Oriented Programming Language</h4><p>C programming language is not traditionally an Object Oriented Language but has influenced the development of Object Oriented Programming <strong>(OOP)</strong> principles and shares certain characteristics with Object Oriented Programming. <br>Object-oriented programming <strong>(OOP)</strong> is a programming paradigm that structures software design around data, or objects, instead of focusing primarily on functions and logic. In this model, an object is described as a data field equipped with distinct attributes and behaviors.<br>OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex, and actively updated or maintained. This includes programs for manufacturing and design, as well as mobile applications; for example, <strong>OOP</strong> can be used for manufacturing system simulation software.<br>Some of C’s features have allowed developers to adopt <strong>OOP-like</strong> practices and these features include:</p><ol><li>structs</li><li>function pointers</li><li>encapsulation through function interfaces</li></ol><p>That being said, C# is an example of a programming language that is object-oriented. Javascript and Typescript on the other hand are both object-oriented and functional programming languages (I will write about functional programming later but like I said earlier functional programming is a type of programming where you deal with functions and logic where you give an input and get an expected output).</p><h4>Typed Language</h4><p>A typed language is one in which variables and values have types. There are languages that determine the types of variables in a program at compile-time. It would interest you to know that C and C# are strongly typed programming languages. They can also be referred to as <strong><em>statically typed languages</em></strong>. <br>Javascript on the other hand is a <strong><em>dynamically typed language. </em></strong>They are dynamic because you can only determine their type at runtime. This comes with a lot of advantages but to make it easy to track types, Typescript was created and it is statically typed.</p><h4>Syntax</h4><p>JavaScript, TypeScript, and C# are in the C family of languages. That similarity means you can already read and understand C#. There are some differences, but most of the syntax is the same as JavaScript and C. The curly braces and semicolons are familiar. The control statements like if, else, switch are the same. The looping statements of for, while, and do...while are same. The same keywords for class and interface are in both C# and TypeScript. The access modifiers in TypeScript and C#, from public to private, are the same. They also share the same async and await keywords for asynchronous programming. C# inheritance is part of the type declaration. A C# class declaration states any base class. In JavaScript, you can set the __proto__ property to set the base type on any instance.</p><h4>Function Hierarchies</h4><p>Javascript, C#, and Typescript languages support scoped/local functions and variables.</p><h4>Package Manager</h4><p>Javascript and Typescript can use either Yarn or NPM as package managers but C# uses NuGet.</p><p>With all this being said, have fun learning these programming languages.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df29a46e7b8d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Looping Through Arrays In Javascript]]></title>
            <link>https://medium.com/@patrickakhamiogu/looping-through-arrays-in-javascript-13eec9eeaeb4?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/13eec9eeaeb4</guid>
            <category><![CDATA[array-methods]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[loops-in-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Thu, 22 Jun 2023 09:35:18 GMT</pubDate>
            <atom:updated>2023-06-22T09:36:58.112Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-Hvq0u4QIq0cONLk" /><figcaption>Photo by <a href="https://unsplash.com/@nateggrant?utm_source=medium&amp;utm_medium=referral">Nate Grant</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are five ways to loop through arrays. They include:</p><ul><li>While loop</li><li>Do-while loop</li><li>For loop</li><li>ForEach loop</li><li>Map loop</li></ul><h3>While Loop</h3><p>A [while] statement executes its statements as long as a specified condition evaluates to true. The syntax for while loops are shown below:</p><pre>while (condition)<br>  statement</pre><p>If the condition becomes false, the statement within the loop stops executing, and control passes to the statement following the loop.</p><p>The condition test occurs <em>before</em> the statement in the loop is executed. If the condition returns true, the statement is executed and the condition is tested again. If the condition returns false, execution stops, and control is passed to the statement following while.</p><p>To execute multiple statements, use a block statement ({ }) to group those statements.</p><p>For example:</p><pre>let n = 0;<br>let x = 0;<br>while (n &lt; 3) {<br>  n++;<br>  x += n;<br>console.log(&#39;value of n&#39;, n)<br>console.log(&#39;value of x&#39;, x)<br>}</pre><p>With each iteration, the loop increments n and adds that value to x. Therefore, x and n take on the following values:</p><ul><li>After the first pass: n = 1 and x = 1</li><li>After the second pass: n = 2 and x = 3</li><li>After the third pass: n = 3 and x = 6</li></ul><p>After completing the third pass, the condition n &lt; 3 is no longer true, so the loop terminates.</p><p>Note that += is a concatenation symbol that either adds/joins two strings together or adds/sums two numbers together</p><h3>DO-While Loop</h3><p>The [do...while] statement repeats until a specified condition evaluates to false. The syntax for a do-while loop is shown below:</p><pre>do<br>  statement<br>while (condition);</pre><p>The statement is always executed once before the condition is checked. (To execute multiple statements, use a block statement ({ }) to group those statements.)</p><p>If the condition is true, the statement executes again. At the end of every execution, the condition is checked. When the condition is false, execution stops, and control passes to the statement following do...while.</p><p>For example,</p><pre>let i = 0;<br>do {<br>  i += 1;<br>  console.log(i);<br>} while (i &lt; 5);</pre><p>The do-while loop <strong>iterates at least once</strong> and reiterates until i is no longer less than 5.</p><h3>For Loop</h3><p>A [for] loop repeats until a specified condition evaluates to false. The JavaScript for loop is similar to the Java and C for loop. The syntax for forloops is shown below:</p><pre>for (the declaration or initialization; the condition; the incrementation or decrementation)<br>  statement</pre><p>When a for loop executes, the following occurs:</p><ol><li>The initializing expression initialization, if any, is executed. This expression usually initializes one or more loop counters, but the syntax allows an expression of any degree of complexity. This expression can also declare variables.</li><li>The condition expression is evaluated. If the value of condition is true, the loop statements execute. Otherwise, the for loop terminates. (If the condition expression is omitted entirely, the condition is assumed to be true.)</li><li>The statement executes. To execute multiple statements, use a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block">block statement</a> ({ }) to group those statements.</li><li>If present, the updated expression afterthought is executed.</li><li>Control returns to Step 2.</li></ol><p>For example,</p><pre>for(i = 0; i &lt; 10; i++){<br>     if(i === 2){<br>         console.log(&#39;2 is my favorite&#39;)<br>           continue<br>};<br>    if(i === 8){<br>         console.log(&#39;find out why the loop broke at 8&#39;)<br>           break<br>};<br>     console.log(&#39;Number&#39; + i)<br>}</pre><h3>ForEach Loop</h3><p>The <strong>forEach()</strong> loop is a method that executes a provided function once for each array element. In order words, a <strong>forEach()</strong> can be seen as an iterating function. The syntax for <strong>forEach()</strong> loop is shown below:</p><pre>forEach(callbackFn)<br>forEach(callbackFn, thisArg)</pre><p>The forEach() method is an iterative method. It calls a provided callbackFn function once for each element in an array in ascending-index order. forEach() always returns <strong>undefined</strong> and is not chainable. The typical use case is to execute side effects at the end of a chain.</p><p>forEach() does not mutate the array on which it is called, but the function provided as callbackFn can. Note, however, that the length of the array is saved <em>before</em> the first invocation of callbackFn. Therefore:</p><ul><li>callbackFn will not visit any elements added beyond the array&#39;s initial length when the call to forEach() began.</li><li>Changes to already-visited indexes do not cause callbackFn to be invoked on them again.</li><li>If an existing, yet-unvisited element of the array is changed by thecallbackFn, its value passed to the callbackFn will be the value at the time that element gets visited.</li></ul><p>The forEach() method only expects the this value to have a length property and integer-keyed properties.</p><p>There is no way to stop or break a forEach() loop other than by throwing an exception. If you need such behavior, the forEach() method is the wrong tool.</p><p>forEach() expects a synchronous function — it does not wait for promises. Make sure you are aware of the implications while using promises (or async functions) as forEach callbacks.</p><h3>callbackFn</h3><p>A function to execute for each element in the array. Its return value is discarded. The function is called with the following arguments:</p><h3>element</h3><p>The current element is being processed in the array.</p><h3>index</h3><p>The index of the current element being processed in the array.</p><h3>array</h3><p>The array forEach() was called upon.</p><h3>thisArg(optional)</h3><p>A value to use as this when executing callbackFn.</p><p>For example,</p><pre>const numbers = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];<br><br>numbers.forEach(number =&gt; console.log(number));<br><br>// Expected output: &quot;a&quot;<br>// Expected output: &quot;b&quot;<br>// Expected output: &quot;c&quot;</pre><p>Note, the forEach() method <strong>returns the elements</strong> in the array.</p><h3>Map Loop</h3><p>The <strong>map()</strong> method <strong>creates and returns a new array</strong> populated with the results of calling a provided function on every element in the calling array. The syntax for the map loop is shown below:</p><pre>map(callbackFn)<br>map(callbackFn, thisArg)</pre><p>The map() method is an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#iterative_methods">iterative method</a>. It calls a provided callbackFn function once for each element in an array and constructs a new array from the results.</p><p>callbackFn is invoked only for array indexes that have assigned values.</p><p>The map() method is a copying method. It does not alter this. However, the function provided as the callbackFn can mutate the array. Note, however, that the length of the array is saved <em>before</em> the first invocation of callbackFn. Therefore:</p><ul><li>callbackFn will not visit any elements added beyond the array&#39;s initial length when the call to map() began.</li><li>Changes to already-visited indexes do not cause callbackFn to be invoked on them again.</li><li>If an existing, yet-unvisited element of the array is changed by callbackFn, its value passed to the callbackFn will be the value at the time that element gets visited.</li></ul><p>The map() method only expects the this value to have a length property and integer-keyed properties.</p><h3>callbackFn</h3><p>A function to execute for each element in the array. Its return value is added as a single element in the new array. The function is called with the following arguments:</p><h3>element</h3><p>The current element is being processed in the array.</p><h3>index</h3><p>The index of the current element being processed in the array.</p><h3>array</h3><p>The array map() was called upon.</p><h3>thisArg (Optional)</h3><p>A value to use as this when executing callbackFn.</p><p>Thanks for reading</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13eec9eeaeb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pointers In C Programming]]></title>
            <link>https://medium.com/@patrickakhamiogu/pointers-in-c-programming-4534b4d296e7?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4534b4d296e7</guid>
            <category><![CDATA[c-programming-language]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[c-program]]></category>
            <category><![CDATA[pointers-in-c]]></category>
            <category><![CDATA[pointers]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Sat, 17 Jun 2023 15:14:25 GMT</pubDate>
            <atom:updated>2023-06-17T15:14:25.061Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p>C is designed to be a low-level language that can easily access memory locations and perform memory-related operations. For instance, the <strong>scanf()</strong> function places the value entered by the user at the location, or <strong>address</strong>, of the variable. This is accomplished by using the &amp; symbol.</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int age;<br>    printf(&quot;Enter an age: &quot;);</pre><pre>    scanf(&quot;%d&quot;, &amp;age);</pre><pre>    printf(&quot;%d&quot;, age);<br>    <br>	return 0;<br>}</pre><p><strong>&amp;age</strong> is the address of variable <strong>age</strong>.</p><p>A memory address is given as a <strong>hexadecimal</strong> number. <strong>Hexadecimal</strong>, or <strong>hex</strong>, is a base-16 number system that uses digits 0 through 9 and letters A through F (16 characters) to represent a group of four binary digits that can have a value from 0 to 15.</p><p>It’s much easier to read a hex number that is 8 characters long for 32 bits of memory than to try to decipher 32 1s and 0s in binary.</p><p>The following program displays the memory addresses for variables <strong>i</strong> and <strong>k</strong></p><pre>#include &lt;stdio.h&gt;</pre><pre>void test(int k);</pre><pre>int main() {<br>    int i = 0;<br>    <br>    printf(&quot;The address of i is %x\\n&quot;, &amp;i);<br>    test(i);<br>    printf(&quot;The address of i is %x\\n&quot;, &amp;i);<br>    test(i);</pre><pre>    return 0;<br>}</pre><pre>void test(int k) {<br>    printf(&quot;The address of k is %x\\n&quot;, &amp;k);<br>}</pre><p>In the printf statement, <strong>%x</strong> is the hex format specifier.</p><p>Program output varies from run to run, but looks similar to:</p><pre>The address of i is 846dd754<br>The address of k is 846dd758<br>The address of i is 846dd754<br>The address of k is 846dd758</pre><p>The address of a variable stays the same from the time it is declared until the end of its scope.</p><h3>Pointers</h3><p>Pointers are very important in C programming because they allow you to easily work with memory locations.</p><p>They are fundamental to arrays, strings, and other data structures and algorithms. A <strong>pointer</strong> is a variable that contains the <strong>address</strong> of another variable. In other words, it “points” to the location assigned to a variable and can indirectly access the variable. Pointers are declared using the * symbol and take the form:</p><pre>pointer_type *identifier</pre><p><strong>Pointer_type</strong> is the type of data the pointer will be pointing to. The actual pointer data type is a hexadecimal number, but when declaring a pointer, you must indicate what type of data it will be pointing to.</p><p>The asterisk * declares a pointer and should appear next to the identifier used for the pointer variable.</p><p>The following program demonstrates variables, pointers, and addresses:</p><pre>int j = 63;<br>int *p = NULL;<br>p = &amp;j; <br>printf(&quot;The address of j is %x\\n&quot;, &amp;j);<br>printf(&quot;p contains address %x\\n&quot;, p);<br>printf(&quot;The value of j is %d\\n&quot;, j);<br>printf(&quot;p is pointing to the value %d\\n&quot;, *p);</pre><p>There are several things to notice about this program:</p><ul><li>Pointers should be initialized to <strong>NULL</strong> until they are assigned a valid location.</li><li>Pointers can be assigned the address of a variable using the <strong>ampersand &amp;</strong> sign.</li><li>To see what a pointer is pointing to, use the * again, as in <strong>p</strong>. In this case, the * is called the <strong>indirection</strong> or <strong>dereference</strong> operator. The process is called <strong>dereferencing</strong>.</li></ul><p><strong>The program output is similar to:</strong></p><pre>The address of j is ff3652cc<br>p contains address ff3652cc<br>The value of j is 63<br>p is pointing to the value 63</pre><p>Some algorithms use a <strong>pointer to a pointer</strong>. This type of variable declaration uses ******, and can be assigned the address of another pointer, as in:</p><pre>int x = 12;</pre><pre>int *p = NULL;</pre><pre>int **ptr = NULL;</pre><pre>p = &amp;x;</pre><pre>ptr = &amp;p;</pre><h3>Pointers in Expression</h3><p>Pointers can be used in <strong>expressions</strong> just as any variable. Arithmetic operators can be applied to whatever the pointer is pointing to.</p><p><strong>For example:</strong></p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int x = 5;<br>    int y;<br>    int *p = NULL;<br>    p = &amp;x;<br>    <br>    y = *p + 2; /* y is assigned 7 */<br>    y += *p;     /* y is assigned 12 */<br>    *p = y;       /* x is assigned 12 */<br>    (*p)++;      /* x is incremented to 13 */</pre><pre>    printf(&quot;p is pointing to the value %d\\n&quot;, *p); <br>}</pre><p>Note that parentheses are required for the ++ operator to increment the value being pointed to. The same is true when using the — operator.</p><h3>Pointers and Arrays</h3><p>Pointers are especially useful with arrays. An array declaration reserves a block of contiguous memory addresses for its elements. With pointers, we can point to the first element and then use <strong>address arithmetic</strong> to traverse the array:</p><ul><li>+ is used to move forward to a memory location</li><li>- is used to move backward to a memory location</li></ul><p><strong>Consider the following program:</strong></p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int a[5] = {22, 33, 44, 55, 66};<br>    int *ptr = NULL;<br>    int i;<br>    <br>    ptr = a;<br>    for (i = 0; i &lt; 5; i++) {<br>        printf(&quot;%d &quot;, *(ptr + i));<br>    }<br>}</pre><p>The program output is 22 33 44 55 66. An important concept with arrays is that an <strong>array name</strong></p><p>acts as a <strong>pointer</strong> to the first element of the array. Therefore, the statement <strong>ptr = a</strong></p><p>can be thought of as <strong>ptr = &amp;a[0]</strong>.</p><h3>Pointers and Functions</h3><p>Pointers greatly expand the possibilities for functions. No longer are we limited to returning one value. With pointer parameters, your functions can alter actual data rather than a copy of data.</p><p>To change the actual values of variables, the calling statement passes addresses to pointer parameters in a function.</p><p>For example, the following program swaps two values:</p><pre>#include &lt;stdio.h&gt;</pre><pre>void swap (int *num1, int *num2);</pre><pre>int main() {<br>    int x = 25;<br>    int y = 100;</pre><pre>    printf(&quot;x is %d, y is %d\\n&quot;, x, y); <br>    swap(&amp;x, &amp;y);<br>    printf(&quot;x is %d, y is %d\\n&quot;, x, y); </pre><pre>    return 0;<br>}<br> <br>void swap (int *num1, int *num2) {<br>    int temp;<br>    <br>    temp = *num1;<br>    *num1 = *num2;<br>    *num2 = temp;<br>}</pre><p>The program swaps the actual values of the variables, as the function accesses them by address using pointers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4534b4d296e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrays In C programming]]></title>
            <link>https://medium.com/@patrickakhamiogu/arrays-in-c-programming-ea55b2f3321f?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea55b2f3321f</guid>
            <category><![CDATA[c-programming-language]]></category>
            <category><![CDATA[c-program]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[c]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 13:20:51 GMT</pubDate>
            <atom:updated>2023-06-17T15:15:56.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p>An <strong>array</strong> is a data structure that stores a collection of related values that are all the same type.</p><p>Arrays are useful because they can represent related data with one descriptive name rather than using separate variables that each must be named uniquely.</p><p>An array has the following syntax:</p><pre>dataType arrayName[arraySize] = {arrayElements};</pre><p>For example, the array <strong>test_scores[25]</strong> can hold 25 test scores. Once declared, the size and the datatype of an array cannot be changed.</p><h3>Accessing Array Elements</h3><p>The contents of an array are called <strong>elements</strong> with each element accessible by an index number.</p><p>In C, index numbers start at <strong>0</strong>.</p><p>An array with 5 elements will have index numbers 0, 1, 2, 3, and 4. Consider an array x:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int x[5] = {20, 45, 16, 18, 22};   <br>    return 0;<br>}</pre><p>It can be thought of as:</p><p>0 =&gt; [20]</p><p>1 =&gt; [45]</p><p>2 =&gt; [16]</p><p>3 =&gt; [18]</p><p>4 =&gt; [22]</p><p>To access an array element, refer to its index number. So in our example above, to access the <strong>First number,</strong> we would write the code like this</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int x[5] = {20, 45, 16, 18, 22};<br>    printf(&quot;The second element is %d\\n&quot;, x[0]); <br>  // This will print the number 20<br>    <br>    return 0;<br>}</pre><p>It is also possible to change the elements in an array using their index number:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int x[5] = {20, 45, 16, 18, 22};<br>     x[3] = 300;<br>    printf(&quot;The second element is %d\\n&quot;, x[3]);<br>    // This will return the number 300 as the second number or third index<br>    return 0;<br>}</pre><p>If we created an array of 5 numbers for instance and only filled it up with 3 elements as shown below:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int x[5] = {20, 45, 16};<br>    printf(&quot;The second element is %d\\n&quot;, x[3]); <br>    printf(&quot;The second element is %d\\n&quot;, x[4]); <br>  // This will print the number 0 for index 3 and 4<br>    <br>    return 0;<br>}</pre><p>the value returned in index 3 and 4 will be 0.</p><h3>Using Loops with Arrays</h3><p>Assuming we wanted to take 5 input values from a user and store these inputs in an array, we can use the <strong>for loop</strong> for this. Here is what the code will look like:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int num[5];<br>    <br>    for (int i = 0; i &lt; 5; i++){<br>        printf(&quot;Enter a number: &quot;);<br>        scanf(&quot;%d&quot;, &amp;num[i]);<br>    }<br>    for (int i = 0; i &lt; 5; i++){<br>        printf(&quot;%d, &quot;, num[i]);<br>    }<br>    return 0;<br>}</pre><h3>Nested Arrays</h3><p>You can think of a nested array (otherwise known as a two-dimensional array) as a grid for representing a chess board, city blocks, and much more.</p><p>For example:</p><pre>int a[2][3] = { {3, 2, 6}, {4, 5, 20} };</pre><p>This array above has two arrays, each containing 3 elements each. To access each element, both the row index and column index are required. For example:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int a[2][3] = {<br>        {3, 2, 6},<br>        {4, 5, 20}<br>    };<br>    printf(&quot;Element 3 in row 2 is %d\\n&quot;, a[1][2]); /* 20 */<br>    a[1][2] = 25;<br>    printf(&quot;Element 3 in row 2 is %d\\n&quot;, a[1][2]); /* 25 */<br>   <br>	return 0;<br>}</pre><p>Just as a <strong>for</strong> loop is used to iterate through an array, nested <strong>for</strong> loops are used to traverse a nested array:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int a[2][3] = {<br>        {3, 2, 6},<br>        {4, 5, 20}<br>    };<br>    <br>    int k, j;<br>    /* display array contents */<br>    for (k = 0; k &lt; 2; k++) {<br>        for (j = 0; j &lt; 3; j++) {<br>            printf(&quot; %d&quot;, a[k][j]);<br>        }<br>        printf(&quot;\\n&quot;);<br>    }<br>   <br>	return 0;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea55b2f3321f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Variable Scope in C Programming]]></title>
            <link>https://medium.com/@patrickakhamiogu/variable-scope-in-c-programming-2ac5801a5e53?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ac5801a5e53</guid>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[c-programming-language]]></category>
            <category><![CDATA[c-program]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 13:07:28 GMT</pubDate>
            <atom:updated>2023-06-17T15:15:35.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p><strong>Variable scope</strong> refers to the visibility of variables within a program. Variables declared in a function are <strong>local</strong> to that block of code and cannot be referred to outside the function. Variables declared outside all functions are <strong>global</strong> to the entire program. For example, constants declared with a <strong>#define</strong> at the top of a program are visible to the entire program. The following program uses both <strong>local</strong> and <strong>global</strong> variables:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int global1 = 0; </pre><pre>int main() {    <br>    int local1, local2;<br>  <br>    local1 = 5;<br>    local2 = 10;<br>    global1 = local1 + local2;<br>    printf(&quot;%d \\n&quot;, global1);  /* 15 */<br>    <br>    return 0;<br>}</pre><p>When arguments are passed to function parameters, the parameters act as local variables. Upon exiting a function, parameters and any local variables in the function are destroyed.</p><p>Use global variables with caution. They should be initialized before using to avoid unexpected results. And because they can be changed anywhere in a program, global variables can lead to hard-to-detect errors.</p><h3>Static Variables</h3><p><strong>Static</strong> variables have a local scope but are not destroyed when a function is exited. Therefore, a static variable retains its value for the life of the program and can be accessed every time the function is re-entered.</p><p>A static variable is initialized when declared and requires the prefix <strong>static</strong>.</p><p>The following program uses a static variable:</p><pre>#include &lt;stdio.h&gt;</pre><pre>void say_hello();</pre><pre>int main() {	<br>    int i;</pre><pre>    for (i = 0; i &lt; 5; i++) {<br>        say_hello();<br>    }<br>   <br>    return 0;<br>}</pre><pre>void say_hello() {<br>    static int num_calls = 1;</pre><pre>    printf(&quot;Hello number %d\\n&quot;, num_calls);<br>    num_calls++;<br>}</pre><p>The program output is:</p><p>Hello number 1</p><p>Hello number 2</p><p>Hello number 3</p><p>Hello number 4</p><p>Hello number 5</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ac5801a5e53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functions in C Programming]]></title>
            <link>https://medium.com/@patrickakhamiogu/functions-in-c-programming-2cb72a4a9e36?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cb72a4a9e36</guid>
            <category><![CDATA[c-programming-language]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[c-program]]></category>
            <category><![CDATA[c-programming]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 17:23:44 GMT</pubDate>
            <atom:updated>2023-06-17T15:18:20.408Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p>A function:</p><ul><li>is a block of code that performs a specific task</li><li>is reusable</li><li>makes a program easier to test</li><li>can be modified without changing the calling program</li></ul><p>Even a simple program is easier to understand when <strong>main()</strong> is broken down into subtasks that are implemented with functions.</p><p>A function takes the following syntax:</p><pre>return_type function_name(parameters){<br>    // body<br>};</pre><p>The <strong>return_type</strong> is the type of value the function sends back to the calling statement. The <strong>function_name</strong> is followed by parentheses. Optional <strong>parameter</strong> names with type declarations are placed inside the parentheses.</p><p>A function is not required to return a value, but a return type must still be in the declaration. In this case, the keyword <strong>void</strong> is used. For example:</p><pre>#include &lt;stdio.h&gt;</pre><pre>void greeting () {<br>    printf(&quot;Good morning!!!&quot;);<br>};</pre><pre>int main() {<br>    // Write C code here<br>   greeting();<br>    return 0;<br>}</pre><h3>Function Prototype</h3><p>When the parameter types and names are included in a declaration, the declaration is called a</p><p><strong>function prototype</strong>.</p><p>For example, the <strong>square</strong> function prototype appears above the main():</p><pre>#include &lt;stdio.h&gt;</pre><pre>// declaration<br>int square (int num);</pre><pre>int main() {<br>    int x, result;<br>  <br>    x = 5;<br>    result = square(x);<br>    printf(&quot;%d squared is %d\\n&quot;, x, result);<br>    <br>    return 0;<br>}</pre><pre>// definition <br>int square (int num) {<br>    int y;</pre><pre>    y = num * num;</pre><pre>    return(y);<br>}</pre><p>Our <strong>square</strong> function returns an integer and takes one parameter of type int. The last step is actually <strong>defining</strong> the function. Function definitions usually appear after the <strong>main()</strong> function. As you can see, the <strong>square</strong> function calculates and returns the square of its parameter. A function can take multiple parameters — in this case, they must be separated by commas. The <strong>return</strong> statement is used to send a value back to the calling statement.</p><h3>Function Parameters</h3><p>A function’s <strong>parameters</strong> are used to receive values required by the function. Values are passed to these parameters as <strong>arguments</strong> through the function call. By default, arguments are passed by value, which means that a copy of data is given to the parameters of the called function. The actual variable isn’t passed into the function, so it won’t change. Arguments passed to a function are matched to parameters by position. Therefore, the first argument is passed to the first parameter, the second to the second parameter, and so on.</p><pre>#include &lt;stdio.h&gt;</pre><pre>int sum_up (int x, int y); </pre><pre>int main() {<br>    int x, y, result;<br>  <br>    x = 3;<br>    y = 12;<br>    result = sum_up(x, y);<br>    printf(&quot;%d + %d = %d&quot;, x, y, result);<br>    <br>    return 0;<br>}</pre><pre>int sum_up (int x, int y) { <br>    x += y;<br>    return(x);<br>}</pre><p>The program output is: 3 + 12 = 15 The values of <strong>x</strong> and <strong>y</strong> were passed to <strong>sum_up</strong>. Note that even though the value of parameter <strong>x</strong> was changed in <strong>sum_up</strong>, the value of argument <strong>x</strong> in main() was not changed because only its value was passed into the parameter <strong>x</strong>.</p><p>The parameters in a function declaration are the <strong>formal parameters</strong>. The values passed to these parameters are the arguments, sometimes called the <strong>actual parameters</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cb72a4a9e36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loops in C Programming]]></title>
            <link>https://medium.com/@patrickakhamiogu/loops-in-c-programming-d9724cac3626?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9724cac3626</guid>
            <category><![CDATA[c-programming-language]]></category>
            <category><![CDATA[loop]]></category>
            <category><![CDATA[c-program]]></category>
            <category><![CDATA[c-programming]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 16:27:45 GMT</pubDate>
            <atom:updated>2023-06-17T15:14:59.184Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p>Loops are codes that can execute statements repeatedly while an expression is true, looping over and over again. An <strong>infinite loop</strong> is one that continues indefinitely because the loop condition never evaluates to false. This may cause a run-time error.</p><p>There are 3 types of loop codes:</p><ol><li>While loops</li><li>Do-While loops</li><li>For loops</li></ol><h3>While loop</h3><p>The <strong>while loop</strong> evaluates a condition before the loop is entered, making it possible that the while statements never execute.</p><p>It takes the form:</p><pre>while (expression) {<br>  statements<br>}</pre><p>An example of a while loop is shown below:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int count = 1;<br>  <br>    while (count &lt; 8) {<br>        printf(&quot;Count = %d\\n&quot;, count);<br>        count++;<br>    }<br>    <br>    return 0;<br>}</pre><p>In the example above, the code will output the <strong>count</strong> variable 7 times, meaning the code will run 7 times.</p><h3>Do-While Loop</h3><p>The <strong>do-while</strong> loop executes the loop statements before evaluating the expression to determine if the loop should be repeated.</p><p>it takes this form:</p><pre>do {<br>  statements<br>} while (expression);</pre><p>An example is shown below:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int count = 1;<br>  <br>    do {<br>        printf(&quot;Count = %d\\n&quot;, count);<br>        count++;<br>    } while (count &lt; 8);<br>    <br>    return 0;<br>}</pre><p>Note the semicolon after the while statement. The <strong>do-while</strong> loop always executes at least once, even if the expression evaluates to false.</p><h3>Note:</h3><p>The <strong>break</strong> statement was introduced for use in the <strong>switch</strong> statement. It is also useful for immediately exiting a loop. For example, the following program uses a <strong>break</strong> to exit a <strong>while</strong> loop:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int num = 5;<br>  <br>    while (num &gt; 0) {<br>        if (num == 3)<br>            break;<br>        printf(&quot;%d\\n&quot;, num);<br>        num--;<br>    } <br>    <br>    return 0;<br>}</pre><p>This program displays:</p><p>5</p><p>4</p><p>and then exits the loop.</p><p>When you want to remain in the loop, but skip ahead to the next iteration, you use the <strong>continue</strong> statement.</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    int num = 5;<br>  <br>    while (num &gt; 0) {<br>    num--;<br>    if (num == 3)<br>      continue;<br>      <br>    printf(&quot;%d\\n&quot;, num);<br>  } <br>}</pre><p>The program output displays:</p><p>4</p><p>2</p><p>1</p><p>0</p><p>As you can see, the value 3 is skipped. In the code above, if <strong>num</strong> was decremented after the</p><p><strong>continue</strong> statement an infinite loop would be created.</p><h3>For Loop</h3><p>The <strong>for loop</strong> is a loop structure that executes statements a fixed number of times.</p><p>It takes the form:</p><pre>for (initvalue; condition; increment) {<br>  statements;<br>}</pre><p>The <strong>initvalue</strong> is a counter set to an initial value. This part of the <strong>for</strong> loop is performed only once. The</p><p><strong>condition</strong> is a Boolean expression that compares the counter to a value before each loop iteration, stopping the loop when false is returned. The <strong>increment</strong> increases (or decreases) the counter by a set value. For example, the program below displays 0 through 9:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    // Write C code here<br>   int sum = 0;<br>  for(int i = 0; i &lt;= 100; i++){<br>      sum = sum + i;<br>      printf(&quot;the sum is:  %d\\n&quot;, sum);<br>  }<br> printf(&quot;the sum of all numbers from 1 - 100 is:  %d\\n&quot;, sum);<br>    return 0;<br>}</pre><p>the code above prints out the sum of all numbers between 1–100</p><p>There are also nested <strong>For loops</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9724cac3626" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conditional Statements in C Programming]]></title>
            <link>https://medium.com/@patrickakhamiogu/conditional-statements-in-c-programming-33954f881ecd?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/33954f881ecd</guid>
            <category><![CDATA[c-program]]></category>
            <category><![CDATA[c-programming-language]]></category>
            <category><![CDATA[conditional-statements]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[ternary-operator]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 16:25:07 GMT</pubDate>
            <atom:updated>2023-06-17T15:17:06.513Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p>Conditional statements are used when you are anticipating certain events to occur and you require some action to be performed when those events happen.</p><p>There are 3 types of conditional statements in the C programming language</p><ol><li>If and else statements</li><li>Ternary operators</li><li>Switch statements</li></ol><h3>The If Else Statement</h3><p>The if-else statement has the following syntax:</p><pre>if (the condition){<br>the first action<br>}else if{<br>the second action<br>} else{<br>the last action<br>}</pre><p>You can have as many “if else” as you want. For example, you want to write a code for a voting app where only persons that are 18 years above are eligible to vote and those below are not eligible, this can be done using an “if else” statement as shown below:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    // Write C code here<br>   int age = 15;<br>   printf(&quot;Please enter your age: &quot;);<br>   scanf(&quot;%d&quot;, &amp;age);<br>if(age &gt;=18){<br>  printf(&quot;You are eligible to vote&quot;);<br>}else {<br>   printf(&quot;You are not eligible to vote&quot;);<br>}<br>    return 0;<br>}</pre><h3>The Ternary Operator</h3><p>The ternary operator has the following syntax:</p><pre>(the condition) ? the first action : the second action;</pre><p>This type of conditional statement is usually used when there are not more than two different scenario actions to be performed. For instance, in the example used in the if-else statement above, the perfect way to write it is to use the ternary operator. Check below:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    // Write C code here<br>   int age;<br>   printf(&quot;Please enter your age: &quot;);<br>   scanf(&quot;%d&quot;, &amp;age);<br>(age &gt;= 18) ?  printf(&quot;You are eligible to vote&quot;) : printf(&quot;You are not eligible to vote&quot;);</pre><pre>    return 0;<br>}</pre><p>This code will give the same result as the if-else statement above.</p><h3>The Switch Statement</h3><p>This type of conditional statement has the following syntax:</p><pre>switch (variable/expression){<br>     case value1:<br>     // body of case 1<br>     break;</pre><pre>     case value2:<br>     // body of case 2<br>     break;</pre><pre>     case value3:<br>     // body of case 3<br>     break;</pre><pre>     default:<br>     // body of the default    <br>   }</pre><p>Now if we were to write the above example using the switch statement, it would look like this:</p><pre>#include &lt;stdio.h&gt;</pre><pre>int main() {<br>    // Write C code here<br>   int age;<br> <br>   printf(&quot;Please enter your age: &quot;);<br>   scanf(&quot;%d&quot;, &amp;age);<br>   </pre><pre>   switch (age &lt; 18){<br>     case 1:<br>     // body of case 1<br>     printf(&quot;you are not eligible&quot;)<br>     break;</pre><pre>     case 2:<br>     // body of case 2<br>     break;</pre><pre>     case value3:<br>     // body of case 3<br>     break;</pre><pre>     default:<br>     // body of the default    <br>   }<br>    return 0;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33954f881ecd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Higher-Order Functions, and Callback Functions]]></title>
            <link>https://medium.com/@patrickakhamiogu/higher-order-functions-and-callback-functions-55641326dca4?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/55641326dca4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[higher-order-function]]></category>
            <category><![CDATA[callback-function]]></category>
            <category><![CDATA[callback]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 10:02:44 GMT</pubDate>
            <atom:updated>2023-06-17T15:16:46.194Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p>Hello and welcome back to my page. I will try to break down these concepts. By the end of this read, you will understand the concepts of <strong><em>Higher-Order functions, and Callback functions</em></strong>, why they are used, and when to use them. These concepts are usually asked during interviews for front-end developers.</p><p>Firstly, let us find out what <strong><em>Higher-Order functions</em></strong> are. <strong><em>Higher-order functions (HOFs) </em></strong>are functions that operate on other functions, either by taking them as arguments or by returning them. Operations here refer to either returning a function as the result OR accepting one or more functions as arguments. It is not required to carry out both tasks. A function is deemed a <strong><em>higher-order funct</em></strong>ion if it does either one or the other.</p><p>The question to ask yourself is: ‘How is this possible? Why can a function take another function as an argument or return a function? How can a function take another function as an argument or return a function?’ Knowing these answers would really help you understand how <strong><em>HOFs </em></strong>work<strong><em> </em></strong>under the hood. Remember your data types? The one you learned when you were taking your first Javascript course? You were told that javascript has two types of data types:</p><ol><li>Primitive Data Types</li><li>Non-Primitive Data Types.</li></ol><p>The primitive data types in plain terms are data types that are not objects and they include <em>Strings, Numbers, Boolean, Symbols, Bigint, Null </em>and<em> Undefined</em>. The non-primitive data types include <em>Arrays,</em> <em>Objects</em>, and <em>Functions</em>. <strong>Now, this might be a bit confusing because a type of object is an <em>Object</em>.</strong> I am trying to draw your attention to this fact because it is very important. Objects are key-based, use methods, and take in properties. <strong>It would interest you to know that an <em>Array</em> is an object that works slightly differently from objects</strong> because they are index-based and use a different type of iterators along with other reasons too (research more on arrays and you will be amazed). It would also interest you to know that <strong>functions are objects too. They are the advanced type of objects in a way.</strong> Just like chess where the queen has the same powers as the rook, bishop, and pawn, functions have all the properties of the function and objects embedded in them. (I play a lot of chess and that&#39;s the best way I can explain functions for you to understand these concepts). JavaScript functions are “<em>first-class</em>” objects. Therefore:</p><ul><li>They have built-in properties and methods, such as the name property and the .toString() method.</li><li>Properties and methods can be added to them.</li><li>They can be passed as arguments and returned from other functions.</li><li>They can be assigned to variables, array elements, and other objects.</li></ul><pre>//Assign a function to a variable originalFunc</pre><pre>const originalFunc = (num) =&gt; { return num + 2 };</pre><pre>//Re-assign the function to a new variable newFunc</pre><pre>const newFunc = originalFunc;</pre><pre>//Access the function&#39;s name property</pre><pre>newFunc.name; //&#39;originalFunc&#39;</pre><pre>//Return the function&#39;s body as a string</pre><pre>newFunc.toString(); //&#39;(num) =&gt; { return num + 2 }&#39;</pre><pre>//Add our own isMathFunction property to the function</pre><pre>newFunc.isMathFunction = true;</pre><pre>//Pass the function as an argument</pre><pre>const functionNameLength = (func) =&gt; { return func.name.length };</pre><pre>functionNameLength(originalFunc); //12</pre><pre>//Return the function</pre><pre>const returnFunc = () =&gt; { return newFunc };</pre><pre>returnFunc(); //[Function: originalFunc]</pre><p>The above are examples that show you how functions behave like objects and with this you can start to understand what I am trying to explain and see functions in a different light.</p><h3>Callback Function</h3><p>A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. That means that a callback function is a type of <strong><em>HOFs.</em></strong></p><p>Higher-order functions allow us to abstract over <em>actions</em>, not just values. They come in several forms. For example,</p><h4>The .reduce() Method</h4><p>The .reduce() method iterates through an array and returns a single value.</p><pre>const arrayOfNumbers = [11, 12, 13, 14];</pre><pre>const sum = arrayOfNumbers.reduce((accumulator, currentValue) =&gt; {</pre><pre>return accumulator + currentValue;</pre><pre>});</pre><pre>console.log(sum); // 50</pre><p>In the above code example, the .reduce() method will sum up all the elements of the array. It takes a callback function with two parameters (accumulator, currentValue) as arguments. On each iteration, accumulator is the value returned by the last iteration, and the currentValue is the current element. Optionally, a second argument can be passed which acts as the initial value of the accumulator.</p><h4>The .map() Method</h4><p>The .map() method executes a callback function on each element in an array. It returns a new array made up of the return values from the callback function.</p><p>The original array does not get altered, and the returned array may contain different elements than the original array.</p><pre>const siblings = [&#39;Paul&#39;, &#39;Francis&#39;, &#39;Faith&#39;, &#39;Purity&#39;];</pre><pre>// add string after each sibling</pre><pre>const announcements = siblings.map(sibling =&gt; {</pre><pre>return sibling + &#39; is my sibling.&#39;;</pre><pre>})</pre><pre>console.log(announcements);</pre><p>In the example code above, the .map() method is used to add &#39; is my sibling.&#39; string at the end of each element in the siblings array.</p><h4>The .filter() Method</h4><p>The .filter() method executes a callback function on each element in an array. The callback function for each of the elements must return either true or false. The returned array is a new array with any elements for which the callback function returns true.</p><pre>const randomNumbers = [14, 21, 52, 24, 49];</pre><pre>const filteredArray = randomNumbers.filter(n =&gt; {</pre><pre>return n &gt; 15;</pre><pre>});</pre><p>In the above code example, the array filteredArray will contain all the elements of randomNumbers but 14.</p><p>Understanding these concepts will help you to understand how closures work. I will write on closures later.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55641326dca4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript’s Bundler Overview]]></title>
            <link>https://medium.com/@patrickakhamiogu/javascripts-bundler-overview-1b5506be4487?source=rss-5d997d6b1dd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b5506be4487</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript-bundling]]></category>
            <category><![CDATA[parcel]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Patrick Akhamiogu]]></dc:creator>
            <pubDate>Thu, 11 Aug 2022 20:34:00 GMT</pubDate>
            <atom:updated>2023-06-17T15:17:38.494Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0R259YDeaPiDsGPvGywXw.jpeg" /></figure><p>Let’s start by defining a JavaScript bundler. A JavaScript bundler is a program that compiles all of your code and its dependencies into a single JavaScript file that is ready for production and can be loaded into a browser. Also, when working with libraries that have numerous dependencies or when your project grows too big for a single file, you can utilize a JavaScript bundler. The fact that a bundler creates a dependency graph as it navigates through your first code files is a terrific feature. This indicates that the module bundler keeps track of both the dependencies of your source files and the requirements of third parties starting from the entry point you selected. This dependency tree ensures that all source code files and related files are kept up-to-date and free of errors.</p><h4>The next question to ask is why would we want to use bundlers.</h4><p>JavaScript hasn’t had a standard for requesting dependencies from your code historically. Older versions of browsers did not understand the modern es6 style of writing javascript code. Es6 style of coding came with features such as “import”, “export” or “require”, arrow functions, JSX, etc. So basically, the bundler bundles all your code into one single file and sends it down to the browser in a way that it would understand your code.</p><p>If you wanted to write a javascript code for a weather web app in the past, for instance, your code would look like this:</p><pre>&lt;head&gt;<br>  &lt;script src=&quot;//code.jquery.com/jquery-1.12.0.min.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;/js/navbar.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;/js/weatherapi.js&quot;&gt;&lt;/script&gt;<br>  &lt;script src=&quot;/js/main.js&quot;&gt;&lt;/script&gt;<br>  &lt;script&gt;<br>  // Here goes some code<br>  &lt;/script&gt;<br>&lt;/head</pre><p>But now, while utilizing a bundler, the files and their dependencies will be combined into a single file, like this:</p><pre>&lt;head&gt;<br>  &lt;script type=&quot;text/javascript&quot; src=&quot;/bundle.js&quot;&gt;&lt;/script&gt;<br>&lt;/head</pre><p>From the above example, it is easy to see why bundlers are very useful. The code above is much easier to read and understand.</p><p>Below are some advantages of using bundlers:</p><ol><li>Many popular module bundlers come with performance optimization features that make your code respond fast on the browser.</li><li>They offer a consistent tooling environment that relieves you of the burden of dependencies.</li><li>Bundlers offer features that boost productivity, such as robust error reporting that makes it easy for programmers to identify and correct issues.</li><li>We can use npm since require() and exports are implemented similarly to Node.js and look for dependencies in the “node modules” directory. On this basis, you can quickly install and publish new libraries and take advantage of the versioning capabilities of npm.</li><li>Some bundlers remove unnecessary code from the final file, leaving only the code your application requires to function.</li></ol><p>There are different types of bundlers but I will only talk about parcel and webpack.</p><h3>Parcel</h3><p>Parcel bundler is a fast build tool that allows developers to configure modules (Js, CSS, and HTML) necessary for development. It is the second most popular bundler, behind webpack.</p><p>To get started, run <strong>npm i parcel</strong>.</p><p>Let’s say you have a sample HTML boilerplate:</p><pre>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;script src=&quot;./index.js&quot;&gt;&lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>After that, run <strong>parcel index.html</strong> to utilize Parcel to create the HTML file.</p><h4>Pros</h4><ol><li>Zero configuration</li></ol><p>Parcel solves the configuration issues faced with Webpack and Browserify providing developers with a performant architecture needed for rapid web development. There’s also multi-asset support like Webpack enabling bundles for all kinds of non-JavaScript assets like CSS, HTML, and images.</p><p>2. Fast</p><p>Parcel is fast providing premium resource optimization features like hot module replacement and lazy loading of split code. <a href="https://www.npmjs.com/package/parcel-bundler">According to the most recent benchmarks</a>, Parcel’s bundling speed is 9.98s, compared to Browserify’s 22.98s and Webpack’s 20.71s. Using Parcel’s built-in caching technique can even deliver quicker results, with a benchmark time of 2.64s.</p><p>3. Asset optimization</p><p>Features like code-splitting allow you to break code files into chunks, thereby reducing load time.</p><h4>Cons</h4><ol><li>Lack of advanced customizations</li></ol><p>As a highly-opinionated bundler, Parcel is perfect for small and medium-sized applications. Nonetheless, making it work for complex applications where you need to modify the configurations might be tedious. In this situation, most developers prefer to use Webpack.</p><h3>Webpack</h3><p>Webpack functions as a transformer, minifier, and optimizer of all types of file resources and assets as well as a static module bundler for JavaScript files thanks to a wealth of advanced and highly customizable features. Not only that. The ecosystem of plugins and loaders for Webpack is also fairly robust.</p><p>Getting started is as simple as running <strong>npm i webpack</strong></p><h4>Pros</h4><ol><li>Multi-resource support</li></ol><p>In addition to providing out-of-the-box support for JS files, Webpack has a rich Plugin ecosystem it relies on to bundle other files like CSS and Images.</p><p>2. Asset optimization</p><p>Features like code-splitting allow you to break code files into chunks, thereby reducing load time. There’s the Hot module replacement that helps you to manage modules without fully reloading the browser. Developers can employ Loaders in preprocessing their files, resulting in a faster app runtime. These and more highly customizable optimization features have made Webpack the most popular JS bundler.</p><p>3. Developers’ productivity</p><p>When working with a complicated task like Module bundling as a developer, it’s crucial to have:</p><ul><li>Extensive documentation.</li><li>A solid ecosystem of third-party tools you can lean on.</li><li>Efficient error debugging process that makes your work easier.</li></ul><p>These three needs are met by Webpack, which provides a vast ecosystem of plugins and loaders as well as source map-powered debugging. Not just that. The core caching technique of Webpack enables programmers to create apps quickly.</p><h4>Cons</h4><ol><li>Complex</li></ol><p>Numerous developers who have a love-hate relationship with Webpack find its complexity to be a double-edged sword. It also has a difficult learning curve and is sophisticated.</p><p>2. Buggy and Slow</p><p>Webpack’s all batteries included approach can sometimes cause Webpack app integrations to be over-engineered. Over-reliance on plugins to do simple functions can cause the bundler to slow W necessitating technical debugging to make it well-optimized.</p><p>3. In a way, not suitable for learners</p><p>Webpack in a way is good for learners because it just gives you all the tools you need to code without necessarily configuring anything. One line of command and you get all you need. Why I will say it&#39;s not suitable for learners is because using that one line of command kinda drops you“ in the middle of your project”, you would not know how you got there or how these packages work “under the hood”. This is opinionated anyway.</p><p>Start using a JavaScript bundler today. Check out <a href="https://parceljs.org/">parcel</a> or <a href="https://webpack.js.org/">webpack</a>.</p><p>Inspired by Brian Holts from <a href="https://frontendmasters.com/">frontend masters</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b5506be4487" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>