<?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 Divine Favour on Medium]]></title>
        <description><![CDATA[Stories by Divine Favour on Medium]]></description>
        <link>https://medium.com/@divine-favour?source=rss-a30501f17248------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0gUYochLCIhdQt8r3qOqpQ.jpeg</url>
            <title>Stories by Divine Favour on Medium</title>
            <link>https://medium.com/@divine-favour?source=rss-a30501f17248------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 17:20:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divine-favour/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[5 Different Ways of Iterating With JavaScript Loops]]></title>
            <link>https://medium.com/better-programming/5-different-ways-of-iterating-with-javascript-loops-fcb223b0f21f?source=rss-a30501f17248------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcb223b0f21f</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Divine Favour]]></dc:creator>
            <pubDate>Wed, 24 Mar 2021 14:36:28 GMT</pubDate>
            <atom:updated>2021-03-24T14:36:28.223Z</atom:updated>
            <content:encoded><![CDATA[<h4>JavaScript loops can make us a lot more productive</h4><figure><img alt="Froot Loops" src="https://cdn-images-1.medium.com/max/1024/0*zfOv8tZj5Cxj7BjW" /><figcaption>Photo by <a href="https://unsplash.com/@kai_wenzel?utm_source=medium&amp;utm_medium=referral">Kai Wenzel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>Sometimes there are certain tasks we would want to run continuously in our program. Instead of rewriting the code each time for the same task, we could easily use loops in JavaScript to repeatedly run these tasks.</p><h3>What Looping Means</h3><p>A loop is a programming feature that iterates a set of tasks or directives as long as a particular condition is met.</p><p>Loops check a condition. If the condition is met (i.e. if it returns true), a set of code will run. The condition is checked again, and if it still returns true, the set of code is run again. This cycle continues until the condition returns false. Once the condition is no longer met (i.e. it returns false), the loop closes.</p><h4>A simple example of loops</h4><p>Assuming we want to change the background-color of just three items in a list of four items, we could write it out like this.</p><p>First, we create the list of items:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7148335d102d70c6fc22085348c49e32/href">https://medium.com/media/7148335d102d70c6fc22085348c49e32/href</a></iframe><p>We then style it using CSS. The background-color is first set to aqua:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95e542cfa4a6585e5b1a4450dd2997f6/href">https://medium.com/media/95e542cfa4a6585e5b1a4450dd2997f6/href</a></iframe><p>To change only the first three items, we would have to loop through the list:</p><pre>var loop = document.querySelectorAll(&quot;li&quot;);<br>for (let i = 0; i &lt; loop.length - 1; i++) {<br>     loop[i].style.backgroundColor = &quot;blue&quot;;<br>}</pre><p>The background-color continues to change until it reaches the third item, which is the condition we set.</p><p>Loops make it very easy to repeat a particular task as long as the required condition is met.</p><h3>Types of Loop Statements</h3><p>There are several types of loop statements. However, they all essentially perform the same task: They repeat an action a certain number of times.</p><p>There are various instances where one type of loop will be more suitable than others.</p><p>The different types of loop statements include:</p><ul><li>A<em> </em>for loop statement</li><li>A for … in loop statement</li><li>A for …of loop statement</li><li>A while loop statement</li><li>A do … while loop statement</li></ul><h4>For loop statement</h4><p>A for loop statement continues to iterate until a specified condition no longer returns true.</p><pre><strong>syntax:<br></strong>for (initialization statement;<em> condition statement </em>;<em> increment statement</em>) {<br>  // <em>code block to be executed</em><br>}</pre><p>If we want to write out the ages of all members of a certain family saved in an array, we could write it out using this statement:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3d12c5286ec66193cc25ef6e02e00b4/href">https://medium.com/media/f3d12c5286ec66193cc25ef6e02e00b4/href</a></iframe><p>A for loop is made up of three statements.</p><p>The initialization statement (i = 0;) is executed only once. The variable i is also known as the <em>index. </em>It acts as a counter. It can be initialized to any number.</p><p>i is first initialized to 0 so the loop can start writing out the ages from the first age item, which is 48.</p><p>Say we want to write out only ages from the index of 2. We can initialize the i variable to 2. i = 2 jumps 48 and 16. It starts writing out the ages from 18.</p><p>The condition statement (i &lt; ageLen;) sets the loop’s condition. The loop continues to run for as long as this condition returns true.</p><p>Here, this is the condition: The loop should write out all the age items as long as i is less than the ageLen, which is equal to 6. The ageLen variable stores the number of items in the age array.</p><p>We could also set the loop to run only if i is less than 5 (i.e. i &lt; 5 ). This will only write out the ages 48 to 14, omitting the last age (11).</p><p>The increment statement<strong> </strong>(i++; or i + 1;) increases the counter by one each time the loop runs. The loop writes out the first age and jumps to the next one until all the ages are written out. This continues only if the condition returns true.</p><p><em>Note: You could also use a decrement statement (</em><em>i — 1).</em></p><h4>For … in loop statement</h4><p>A for…in loop statement runs continuously through the properties of an object. For each property, a particular code block is executed.</p><pre><strong>syntax:<br></strong>for (properties in object) {<br>  // <em>code block to be executed</em><br>}</pre><p>The following example loops through the properties of the company object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1b7b4dc5b92daac8bfaec90ac5bb022/href">https://medium.com/media/b1b7b4dc5b92daac8bfaec90ac5bb022/href</a></iframe><p><em>Tip:</em><strong><em> </em></strong><em>Use the </em><em>for loop or </em><em>while loop when iterating through arrays because the </em><em>for...in statement iterates over user-defined properties together with the array elements.</em></p><h4>For … of loop statement</h4><p>The for…of loop statement runs continuously through the values of an iterable data type, like arrays, maps, sets, strings, etc.</p><pre><strong>syntax:</strong><br>for (values of iterable) {<br> // <em>code block to be executed</em><br>}</pre><p>The example below demonstrates a simple for…of loop statement:</p><pre>var arr = [2, 4, 6];<br>let val;<br>for (val of cars) {<br>  console.log(val);<br>}<br>/* console logs 2, 4, 6... */</pre><h4>While loop statement</h4><p>A while loop statement executes a block of code as long as a specified condition evaluates to true. A while loop is very similar to a for loop.</p><pre><strong>syntax:</strong><br>while (<em>condition</em>) {<br><em> // code block to be executed</em><br>}</pre><p>In the following example, the code in the loop will continue to run as long as the variable i is less than 5:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1d0eaad3faddbc7bef07c540650fb37/href">https://medium.com/media/c1d0eaad3faddbc7bef07c540650fb37/href</a></iframe><h4>Do … while loop statement</h4><p>The do...while loop statement is a different kind of while loop. This loop will execute the code block once before checking if the condition is true. Then it will repeat the loop as long as the condition is true.</p><pre><strong>syntax:</strong><br>do {<br><em> // code block to be executed<br></em>}<br>while (<em>condition</em>);</pre><p>We could rewrite the while loop example above like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/972bf2850a73c87427e50e65010206d3/href">https://medium.com/media/972bf2850a73c87427e50e65010206d3/href</a></iframe><h3>Break and Continue Statements</h3><h4>Break statement</h4><p>The break statement is used to close a loop or stop any iteration.</p><p>In the example below, the break statement ends the loop once i === 2:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/556a04fc0029162d3d4220657fa2dc7f/href">https://medium.com/media/556a04fc0029162d3d4220657fa2dc7f/href</a></iframe><h4>Continue statement</h4><p>The continue statement skips one iteration in the loop. If a certain condition occurs, it then proceeds to the next iteration in the loop.</p><p>In the example below, the continue statement skips 6:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1aecdfdfc71ad08a7c67111f7835b9f/href">https://medium.com/media/b1aecdfdfc71ad08a7c67111f7835b9f/href</a></iframe><h4>Labels</h4><p>A label gives a statement an identifier that you can use to refer to it elsewhere in your code. As noted in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label">MDN Web Docs</a>, “You can use a label to identify a loop, and then use the break or continue statements to indicate whether a program should interrupt the loop or continue its execution.”</p><p>The continue statement (with or without referencing a label) can only be used to skip one loop iteration.</p><p>Without referencing a label, the break statement can only be used to close a loop or an iteration. With a label reference, the break statement can be used to close a specified code block:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50ca08fcc550e7551bdd1983c6a0bfd7/href">https://medium.com/media/50ca08fcc550e7551bdd1983c6a0bfd7/href</a></iframe><h3>Conclusion</h3><p>In this article, we reviewed all the loop statements and how to use them to iterate certain tasks in our program.</p><p>Thanks for reading. I hope you found this article insightful.</p><h3><strong>Resources</strong></h3><p><a href="https://www.w3schools.com/js/js_loop_for.asp">W3schools<br></a><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#labeled_statement">MDN Docs</a><br><a href="https://eloquentjavascript.net/02_program_structure.html">Eloquent JavaScript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcb223b0f21f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/5-different-ways-of-iterating-with-javascript-loops-fcb223b0f21f">5 Different Ways of Iterating With JavaScript Loops</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding and Applying Closures in JavaScript]]></title>
            <link>https://medium.com/better-programming/understanding-and-applying-closures-in-javascript-c0a321e59f1f?source=rss-a30501f17248------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a321e59f1f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Divine Favour]]></dc:creator>
            <pubDate>Tue, 23 Mar 2021 14:27:10 GMT</pubDate>
            <atom:updated>2021-03-23T14:28:09.354Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn closures in the simplest way possible</h4><figure><img alt="Lightbulbs" src="https://cdn-images-1.medium.com/max/1024/0*TJcTJMGD4ma0_zYx" /><figcaption>Photo by <a href="https://unsplash.com/@dragos126?utm_source=medium&amp;utm_medium=referral">Dragos Gontariu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>I remember the first time I came across the term <em>closure</em>.<strong> </strong>It<strong> </strong>was on an Instagram post listing out some important JavaScript topics.</p><p>After seeing this post, I tried to find a simple tutorial on closures. I went through so many examples, but I still wasn’t getting a grasp on it. Most of the tutorials I came across online never gave real examples that could be easily implemented. This made it very difficult for me to know how and where to use closures.</p><p>At some point, I thought of just forgetting the topic and advancing to other JavaScript topics. Closures may indeed seem very overwhelming.</p><p>However, once you get the hang of them, you’ll instantly become a much better programmer.</p><h3>What Closures Really Are</h3><p>A closure is a feature on JavaScript that allows you to access a parent function’s scope from a nested or a child function.</p><p>In their simplest form, closures are functions with preserved data. A closure is created every time a function is created.</p><p>Closures give us the ability to store data in a separate scope and access it only when necessary.</p><p>A simple reason why we need closures is to give some of our data privacy. Sometimes we want to define variables that should only be accessed from a specific part of the script. Closures are best suited for such cases.</p><h4>A simple example</h4><p>In this example, we will create a function that is nested inside another function. The child function accesses the variable stored in the parent function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7f4992d06e0e003565822909ac83407/href">https://medium.com/media/c7f4992d06e0e003565822909ac83407/href</a></iframe><p>Here, we have a function named returnMsg that has access to the variable of the parent function writeMsg. This implies that returnMsg has access to the msg variable. In this example, returnMsg is the closure.</p><h4>A practical example</h4><p>Closures can come in very handy when you want to associate data with a function that operates on that data. This is similar to object-oriented programming, where objects allow you to associate the object’s properties with one or more methods.</p><p>Therefore, you can use a closure anywhere that you might normally use an object with only one method.</p><p>Instances where you might want to do this are very common. Most of the code written in frontend JavaScript is event-based (it takes effect only when a user interacts with the web page in a certain type of way). You define some behavior and then attach it to an event that is initiated by the user (such as a click or a double-click). The code is attached as a callback (a single function that is executed in response to the event).</p><p>For instance, assuming we want to add buttons to a page to adjust the width and height of a div element anytime a user clicks on any of the buttons:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3efc713bbd5816fe2017b7b94e0f41d3/href">https://medium.com/media/3efc713bbd5816fe2017b7b94e0f41d3/href</a></iframe><p>Here, the width and height are first set to 60px and 50px, respectively.<br>We created three buttons. Each of them increases the div element to a particular size anytime the user clicks on it. Each button calls a function.</p><p>The increment is done by the adjustOne, adjustTwo, and adjustThree functions inside the adjust function.</p><h4>Another example</h4><p>Suppose we want to create a counter that increases the number of claps when the user clicks on a button:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95ea515784cde7f0aba5c8cd597ea320/href">https://medium.com/media/95ea515784cde7f0aba5c8cd597ea320/href</a></iframe><p>A parent arrow function that is self-invoked is created. The number of claps is first initialized to 0 inside the parent function addClap. A child function is used to increase the counter by one anytime the user clicks on the button.</p><p>From this, we can see that the clapCounter variable was declared outside the child function, but we were able to access it from inside it.</p><p>This is basically the simplest form of closures.</p><h3>Closure Scope Series</h3><p>A closure has three scope series:</p><ul><li>A lexical scope or static scope. This scope accesses its own variables.</li><li>A parent function scope. This scope accesses the variables of its parent function.</li><li>Global scope. This accesses any variable outside a function (i.e. global variables).</li></ul><h4>Lexical scope</h4><p>Lexical scoping means that a variable defined outside a function can be accessible inside another function. However, the reverse does not hold true. The variables defined inside the inner function cannot be accessed outside that function.</p><p>This means that variables of parent functions can be accessed by their child function, but variables of child functions cannot be accessed by parent functions.</p><p>Suppose I have a parent function x with variables defined inside it and a child function y that also has variables defined inside it. The variables of y can only be accessed inside y. It is private, while the variables of x can be accessed in both functions x and y.</p><p>A lexical scope is also referred to as a static scope. The concept of lexical scoping is widely used in closures.</p><p>A simple example to demonstrate a lexical scope:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85ce31b8991b685b4fb5acaaf833d148/href">https://medium.com/media/85ce31b8991b685b4fb5acaaf833d148/href</a></iframe><p>In the code snippet above, two functions were created: myFunction() and mySecondFunc(). myFunction() is the parent function that has a function scope, while mySecondFunc() is the child function that has a lexical scope. Both functions have variables defined inside them (age and hobby, respectively).</p><p>The age variable can be accessed from inside both functions, but the hobby variable can only be accessed inside the mySecondFunc() function.</p><p>The name variable has a global scope, so it can be accessed from anywhere in the script.</p><p><em>Tip: Avoid using global variables.</em></p><h3>Conclusion</h3><p>This is as far as I will go in this overview of closures. You might have been using closures without even realizing it, but if you haven’t, give them a try.</p><p>From here on out, when you see closures in your code or any code you see on the web, you can easily pinpoint them, see what they are doing, and why they are being used.</p><p>There is nothing more to it than practice. You now have the basic knowledge. Dig into some existing code — whether it’s yours or any code you can lay your hands on — and try to identify the closures and why they are used. The more you practice using closures, the better you’ll understand the topic.</p><p>Thanks for reading. I hope this article helped you better understand closures.</p><p>Reach out and ask me questions in the comments if you have any!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a321e59f1f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/understanding-and-applying-closures-in-javascript-c0a321e59f1f">Understanding and Applying Closures in JavaScript</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[8 JavaScript Guidelines To Help You Write Better Codes]]></title>
            <link>https://divine-favour.medium.com/8-javascript-guidelines-to-help-you-write-better-codes-137fc6b9cd0a?source=rss-a30501f17248------2</link>
            <guid isPermaLink="false">https://medium.com/p/137fc6b9cd0a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Divine Favour]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 21:29:55 GMT</pubDate>
            <atom:updated>2021-03-21T01:20:11.542Z</atom:updated>
            <content:encoded><![CDATA[<h4>Start writing code that stands out.</h4><figure><img alt="A laptop with codes written in it" src="https://cdn-images-1.medium.com/max/1024/0*NKFhDA2AcsONCgA2" /><figcaption>Photo by <a href="https://unsplash.com/@oskaryil?utm_source=medium&amp;utm_medium=referral">Oskar Yildiz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Writing good code is simple as it is tricky. The rules below may seem like the most common or logical thing to do, but when you look around the web or go through other developer&#39;s codes, you will realize that the “common or logical thing to do” is not very common in most codes.</p><p>Understanding and adhering to the rules below will make you a more effective developer and will allow other developers to build upon your work more effortlessly.</p><h3>1. Reduce Activities in a Loop</h3><p>Loops are often used in JavaScript to perform repeated tasks based on a condition without re-writing the task each time.</p><p>The common mistakes are declaring the index(i) variable inside the loop, or accessing the length property of an element inside the loop. This means that every time the loop runs, JavaScript needs to access the length property of the element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/540b35c58e9a7f0e6539e5adc7e336ea/href">https://medium.com/media/540b35c58e9a7f0e6539e5adc7e336ea/href</a></iframe><p>You can avoid this by storing the length property in a different variable outside the loop. Placing certain statements outside loops will make the loop run faster.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8edef2d6caf71e165fa45ffd8874ebf/href">https://medium.com/media/a8edef2d6caf71e165fa45ffd8874ebf/href</a></iframe><h3>2. Caching DOM Access</h3><p>Accessing the DOM can be a bit slow compared to other JavaScript statements. This is very obvious when handling complex web applications where your computer is already executing other tasks, alterations made on the DOM may take some time before taking effect.</p><p>To avoid slowing the browser&#39;s overall runtime, store DOM access as variables, so you can use it without re-accessing the DOM continually.</p><pre>//DOM access should be stored in variables for improved performance…</pre><pre>var DOM = document.getElementById(“demo”);</pre><pre>DOM.innerHTML = “Hello World”;</pre><h3>3. Break Up and Organize Code Based on the Task It Executes</h3><p>The act of breaking up and organizing code based on the task it performs is called <strong>MODULARIZING</strong>.</p><p>Modules are codes with individual functionalities.</p><p>Creating functions for each task makes your code reusable and easier to debug and manage. Most times you tend to write the same lines of codes for different functions, in cases like this, it is best to create a generic function that allows you to reuse some functionality.</p><h3>4. Use Shortcut Notations Only When It Makes Sense</h3><p>Shortcut notations make your code small and save time, but it might make your code a bit more difficult to understand for developers who do not know the shortcuts. In this instance, you should always comment on your code.</p><h4>Arrays can be written in any of the two ways:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ced5d00b9661e19ad84276a91433d76/href">https://medium.com/media/9ced5d00b9661e19ad84276a91433d76/href</a></iframe><p>There is no need to use new Array(). For simplicity and readability, it is better to use the second code example.</p><h4>Conditional statements can be shortened using the ternary notation:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e1843db5f46131d51f4a1f78193e614/href">https://medium.com/media/5e1843db5f46131d51f4a1f78193e614/href</a></iframe><h4>An arrow function can be used to write functions in a shorter form:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed63ee82a5677361d76bbd4304a0d6be/href">https://medium.com/media/ed63ee82a5677361d76bbd4304a0d6be/href</a></iframe><p>Functions are best written with ES6’s arrow function.</p><h4>Objects are better written with literal notation rather than constructor notation:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/152c8fbe8b2fe04133317d36c8a1d8fb/href">https://medium.com/media/152c8fbe8b2fe04133317d36c8a1d8fb/href</a></iframe><p>Objects are better written with the literal notation rather than the constructor notation as it avoids unnecessary repetition of object names when accessing the objects</p><h3>5. Avoid Using Global Variables and Functions Names</h3><p>Global variables are declared outside the function or declared with a window object. It can be accessed from anywhere in the code. It is best to avoid using variables and function names with global scope.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/861a08be5e1acbfb4f546b2bf299031d/href">https://medium.com/media/861a08be5e1acbfb4f546b2bf299031d/href</a></iframe><p>To prevent this, use object literal or module pattern to write variables or function names.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65ab0bc231890ebe29c556a9c3704865/href">https://medium.com/media/65ab0bc231890ebe29c556a9c3704865/href</a></iframe><h3>6. Always Stick to Strict Coding Style</h3><p>Most browsers overlook slack codes. However, this shouldn’t be a reason for you to write codes without adhering to strict coding styles.</p><p>Use the “use strict” literal expression to indicate that the code should be executed in strict mode.</p><p>For comparison operators like; ==, != use their strict forms; ===, !== .<br>The strict form of comparison operators checks for both the data type and value, unlike the regular comparison operators which only check for the value.</p><p>You could also check your code’s quality with <a href="http://www.jslint.com/">JSLint</a> a javaScript validation tool that gives you a report about the syntax warnings and their meaning.</p><h3>7. Stick to the Correct Naming Conventions</h3><p><strong>Naming conventions</strong> are rules for choosing the character sequence to be used for identifiers that denote variables, functions, and other data types in a code.</p><p>Always use these same naming conventions for all your code.</p><ul><li>Variable and function names are written as <strong>camelCase</strong></li><li>Constants (like PI) are written in <strong>UPPERCASE</strong></li></ul><p>In JavaScript, you can use <strong>camelCase</strong> or <strong>under_scores</strong> in variable names.<br>Do not use <strong>hyp-hens</strong>, as it may be misunderstood as a subtraction sign.</p><p>In addition to following the correct naming conventions, always name variables, functions, or other data types about the task they perform.</p><h3>8. Always Comment on Your Code</h3><p><strong>Commenting</strong> is the act of writing short notes that explains how your code works throughout your code. Comments explain how your codes work.</p><p>They are added to make the source code easier for other developers to understand, and are usually ignored by compilers and interpreters.</p><h4>Single-line comments:</h4><p>Single line comments start with //.<br>Any text or code between // and the end of the line will be ignored by JavaScript.</p><h4>Multi-line comments:</h4><p>Multi-line comments start with /* and end with */.<br>Any text or code between /* and */ will be ignored by JavaScript.</p><h3>Conclusion</h3><p>There you have it — 8 JavaScript Guidelines To Help You Write Better Codes</p><p>Now get out there and start using your newfound magical coding powers to conquer the world!</p><p><strong>Note that;</strong> Good code is readable, simple, maintainable, and can be easily worked on by other developers. Do not resolve to write code that just “works.” Write code that stands out.</p><p>Thanks for reading. I hope this article was helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=137fc6b9cd0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>