<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dennis Ng'ang'a Mbugua</title>
    <description>The latest articles on DEV Community by Dennis Ng'ang'a Mbugua (@mbuguadennis).</description>
    <link>https://dev.to/mbuguadennis</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1044786%2F3198cf30-0597-4533-8f8d-0b922c07cef0.png</url>
      <title>DEV Community: Dennis Ng'ang'a Mbugua</title>
      <link>https://dev.to/mbuguadennis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mbuguadennis"/>
    <language>en</language>
    <item>
      <title>React Learning Basic to Advance</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Thu, 12 Oct 2023 10:56:50 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/react-learning-basic-to-advance-3n2p</link>
      <guid>https://dev.to/mbuguadennis/react-learning-basic-to-advance-3n2p</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;React is a popular Javascript library useful in creating reusable, component-driven user interfaces for web pages and apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does React work?
&lt;/h3&gt;

&lt;p&gt;React uses its markup language called JSX. JSX makes it easier for React to combine HTML and Javascript Functionality. One of the most powerful features of React is its ability to manage the flow of data throughout the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of JSX
&lt;/h3&gt;

&lt;p&gt;As we have already said, with JSX, you can write Html with Javascript. This has several benefits which include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It makes your code readable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It lets you use the full programmatic power of Javascript within HTML.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: JSX is similar to the HMTL code that you have already learned. However, key differences between HTML and JSX syntax exist which you will continue to learn as we progress with our learning.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  How to write Javascript in JSX?
&lt;/h3&gt;

&lt;p&gt;JSX is a syntactic extension of Javascript, thus you can write Javascript within JSX. To include Javascript in JSX, you need to write your Javascript code within curly braces(&lt;code&gt;{}&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Example&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;code here is treated as Javascript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How is JSX compiled?
&lt;/h3&gt;

&lt;p&gt;JSX is not a valid Javascript, it must be compiled into javascript. The transpiler Babel is a popular tool that is used for this process. Check &lt;a href="https://babeljs.io/"&gt;How transpiler Babel works&lt;/a&gt;. Writing a syntactically invalid JSX will make your code fail.&lt;/p&gt;

&lt;h3&gt;
  
  
  How React renders your code?
&lt;/h3&gt;

&lt;p&gt;Imagine that you need to draw on a piece of paper. You would have to plan and arrange where each of your drawings will go on your paper. But now, you have a magic box that will place your content on the piece of paper. You just need to tell the magic box to take your drawings and stick them on the paper.&lt;/p&gt;

&lt;p&gt;Just like you told the magic box to stick your drawings on the paper, React calls a function &lt;code&gt;ReactDOM.render(JSX, document.getElementById('root')).&lt;/code&gt; This function is what places the JSX code in its lightweight representation of the DOM. React then uses snapshots of its own DOM to optimize updating only specific parts of the actual DOM.&lt;/p&gt;

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

&lt;p&gt;Thanks for diving into this article! By reading it, you've gained insights into how React creates stunning user interfaces. As we journey through our ongoing series about learning React, I'll be explaining more exciting things. Stay tuned for more valuable information and happy learning!&lt;/p&gt;

&lt;h3&gt;
  
  
  Written by &lt;strong&gt;Dennis Mbugua&lt;/strong&gt;
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Follow me on &lt;a href="https://twitter.com/mbugua_dennis33"&gt;Twitter X&lt;/a&gt;
&lt;/h2&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Object Destructuring in JavaScript</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Mon, 21 Aug 2023 11:48:31 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/object-destructuring-in-javascript-4pl9</link>
      <guid>https://dev.to/mbuguadennis/object-destructuring-in-javascript-4pl9</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;As a Javascript developer, you will work with different data types on a daily basis including objects.&lt;br&gt;
Objects help in storing data in a structured manner. Objects can also represent real-world objects like dogs.&lt;br&gt;
When it comes to objects, data is stored in properties, each property having a value.&lt;br&gt;
Therefore, when working with objects in Javascript, you will often need to extract specific properties from an object.&lt;br&gt;
&lt;em&gt;Object destructuring&lt;/em&gt; is a syntax introduced in ES6 that provides a net way of assigning values taken directly from an object.&lt;br&gt;
Object destructuring is useful for writing clean and readable code.&lt;br&gt;
In this guide, you will explore object destructuring  step by step.'&lt;br&gt;
When you are done reading, you will be able to streamline your Javascript code using object destructuring.&lt;/p&gt;
&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;Before we continue with this guide, you should have the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic understanding of HTML AND CSS.  &lt;a href="https://developer.mozilla.org/enUS/docs/Learn/Getting_started_with_the_web/HTML_basics"&gt;Get Started with HTML and CSS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Knowledge of basic Javascript. &lt;a href="https://developer.mozilla.org/enUS/docs/Learn/Getting_started_with_the_web/JavaScript_basics"&gt;You can get started with Javascript basics here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Knowledge of how to use the console to write your javascript code
&lt;a href="https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/console/console-javascript"&gt;learn how to use Google console to run Javascript&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Understand basic ES6 syntax including arrow functions&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Basic destructuring using assignment operator
&lt;/h2&gt;

&lt;p&gt;Destructuring assignment is a special syntax in ES6 that enables us to extract properties from an object and assign them to variables in one line.&lt;/p&gt;

&lt;p&gt;For example, consider the object below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const  user ={
    firstName: "John",
    lastName: "Doe",
    age:25,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In  ES5,  you could extract properties like this;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const firstName = user.firstName;
const lastName = user.lastName;
const age = user.age;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In this example,  &lt;code&gt;firstname&lt;/code&gt; would have the value of the string &lt;strong&gt;John&lt;/strong&gt;, &lt;code&gt;lastName&lt;/code&gt; would be &lt;strong&gt;Doe&lt;/strong&gt;, and &lt;code&gt;age&lt;/code&gt; would have the value of the number  &lt;strong&gt;25&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Using  ES6 object destructuring syntax, the following is the equivalent code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const {firstName,lastName,age } = user;


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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Again, here, &lt;code&gt;firstname&lt;/code&gt; would have the value of the string &lt;strong&gt;John&lt;/strong&gt;, &lt;code&gt;lastName&lt;/code&gt; would be &lt;strong&gt;Doe&lt;/strong&gt;, and &lt;strong&gt;age&lt;/strong&gt; would have the value of the number &lt;strong&gt;25&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can extract as many or as few values from an object as you want&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Assign variables to properties while destructuring
&lt;/h2&gt;

&lt;p&gt;Object destructuring allows you to assign variables to properties when extracting values.&lt;br&gt;
To do this, put a new name after a colon when assigning the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- Javascript code --&amp;gt;
const  user ={
    firstName: "John",
    lastName: "Doe",
    age:25,
}

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

&lt;/div&gt;



&lt;p&gt;Here is how you can give a new variable to a property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const {firstName: userFirstName, lastName:userLastName, age : userAge} =user;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may read this code as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get the value of &lt;code&gt;user.firstName&lt;/code&gt; and assign it to a variable named &lt;code&gt;userFirstName&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt; Get the value of &lt;code&gt;user.lastName&lt;/code&gt; and assign it to a variable named &lt;code&gt;userLastName&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt; Get the value of &lt;code&gt;user.age&lt;/code&gt; and assign it to a variable named &lt;code&gt;userAge&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Again the variable userFirstName would have the value of the string &lt;code&gt;John&lt;/code&gt;, &lt;code&gt;userLastName&lt;/code&gt; would have  &lt;strong&gt;Doe&lt;/strong&gt;, and &lt;code&gt;userAge&lt;/code&gt; would have the value of the number &lt;strong&gt;25&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Assign variables to nested objects
&lt;/h2&gt;

&lt;p&gt;Sometimes you will work with an object that contains other objects inside it which we refer to as object nesting.&lt;br&gt;
We can use ES6 syntax to destructure values from a nested object.&lt;/p&gt;

&lt;p&gt;To achieve this, we will nest &lt;code&gt;johnDoe&lt;/code&gt; as an object inside a &lt;code&gt;user&lt;/code&gt; object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = {
    johnDoe :{
        age:25,
        email:"johndoe@gmail.com"

    }

};

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

&lt;/div&gt;



&lt;p&gt;In the above code, we have a user object that has johnDoe object nested within it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Firstly, here is how you can extract the values of the object's properties and assign them to variables with the same name:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- Javascript code --&amp;gt;
const { johnDoe: {age, email}} = user;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Secondly, here is how you can assign an object's properties values to variables with different names:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- javascript code --&amp;gt;
const {johnDoe:{age:userAge, email:userEmail}} = user;


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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use Destructuring assignment to assign variables from Arrays
&lt;/h2&gt;

&lt;p&gt;Destructuring assignment is not limited to objects. We can also destructure values from arrays just as we have done with objects.&lt;br&gt;
The following example shows how you can use destructuring assignment to assign variables from arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- JavaScript code --&amp;gt;
const myName=  ["Dennis", "John", "Doe"]; // an array of names

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

&lt;/div&gt;



&lt;p&gt;Here is how to use destructuring assignment and assign variables from the arrays:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- JavaScript Code --&amp;gt;

const[firstName, secondName,lastName] = MyName;


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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;The variable &lt;code&gt;firstName&lt;/code&gt; would have the value of the string &lt;code&gt;Dennis&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The variable &lt;code&gt;secondName&lt;/code&gt; would have the value of the string &lt;code&gt;John&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The variable &lt;code&gt;lastName&lt;/code&gt; would have the value of the string &lt;code&gt;Doe&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Destructuring via rest elements
&lt;/h2&gt;

&lt;p&gt;Sometimes in array destructuring, you may want to collect the rest of the elements in a separate sub-array.&lt;br&gt;
The rest parameter allows functions to accept an indefinite number of arguments as an array.&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters"&gt;read more on rest paremeter in JavasScript&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the following example, we have an array that contains 3 colors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [firstColor,secondColor, ...remainingColors] = ["red", "green", "blue", "yellow", "black"];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when you console.log the variables, the following values are displayed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(firstColor); // red
console.log(secondColor); // green
console.log(remainingColors); // ["blue", "yellow", "black"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variables firstColor and secondColor takes the first and second values from the array. After that, because of the presence of the rest syntax, remainingColors gets the remaining colors in the form of an array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use destructuring assignment to pass an object's properties as function parameters
&lt;/h2&gt;

&lt;p&gt;With object destructuring, you can pass object's properties as function's parameters. Doing this ensures your code is readable.&lt;/p&gt;

&lt;p&gt;Let me explain how to do this :&lt;/p&gt;

&lt;p&gt;Firstly, we have an object &lt;code&gt;personDetails&lt;/code&gt; with properties and values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const personDetails = {
    name:"John Doe",
    age: 25,
    email:"johndoe@gmail.com"

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

&lt;/div&gt;



&lt;p&gt;Secondly, we define an arrow function &lt;code&gt;showPersonInfo&lt;/code&gt; that takes an object with properties &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt;, and &lt;code&gt;email&lt;/code&gt; as its parameter.&lt;br&gt;
when the function is called, it logs a string that contains the person's name, age, and email.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const  showPersonInfo= ({name, age, email})=&amp;gt;{
    console.log(` My name is ${name}.I am  ${age} years old. contact met via ${email}`);


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

&lt;/div&gt;



&lt;p&gt;Thirdly, we invoke &lt;code&gt;showPersonInfo&lt;/code&gt; function and pass the &lt;code&gt;personDetails&lt;/code&gt; object as an argument.&lt;br&gt;
By doing this, you have extracted the &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt;, and &lt;code&gt;email&lt;/code&gt; properties from &lt;code&gt;personDetails&lt;/code&gt;.  You now can access and use the properties inside the function's body.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- javascript code --&amp;gt;
 console.log(showPersonInfo(personDetails));   // My name is John Doe.I am  25 years old. contact me via johndoe@gmail.com

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

&lt;/div&gt;



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

&lt;p&gt;I hope you enjoyed this article. You have learned object destructuring which is an important javascript technique. We have learned how to extract specific values from an object's properties.&lt;br&gt;
Along the way, we have understood how object destructuring enhances code clarity by reducing redundancy hence boosting developer efficiency.&lt;br&gt;
I hope you will use this newly gained knowledge as you continue your Javascript journey.&lt;/p&gt;

&lt;p&gt;Written by: &lt;strong&gt;Dennis Mbugua&lt;/strong&gt;&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/mbugua_dennis33"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>How To Create color Flipper using vanilla Javasscript</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Tue, 25 Jul 2023 16:33:18 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/how-to-create-color-flipper-using-vanilla-javasscript-34hl</link>
      <guid>https://dev.to/mbuguadennis/how-to-create-color-flipper-using-vanilla-javasscript-34hl</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Javascript is used in creating web pages. Javascript allows adding dynamic behaviour and interactivity user experience. &lt;br&gt;
A colour flipper is a simple interactive tool that changes the background color of the HTML element by clicking a button. With the click of a button, a function is run that generates a random colour on the set Background.&lt;br&gt;
Practice makes perfect and to understand Javascript concepts, one needs substantial time and consistency in practice.&lt;br&gt;
The colour flipper is a basic project and understanding how it works will give you a hands-on- approach to a practical understanding of javascript concepts.&lt;br&gt;
In this article, you are going to dive into a colour flipper project using HTML, CSS, and JAVASCRIPT.&lt;br&gt;
When you are finished, you will have covered the following;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DOM manipulation&lt;/li&gt;
&lt;li&gt;Javascript arrays&lt;/li&gt;
&lt;li&gt;Math. random()&lt;/li&gt;
&lt;li&gt;Math. floor()&lt;/li&gt;
&lt;li&gt;Javascript functions&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;Before you dive into this blog, you need to have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual Studio Code installed to write your HTML, CSS, AND JavaScript code. Follow this link to  &lt;a href="https://code.visualstudio.com/"&gt;Download Visual Studio Code&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Working with files. You can successfully create folders, files and navigate through them in VSCode. Get started with this on &lt;a href="https://developer.mozilla.org/en-US/docs/Learn"&gt;Mozilla Developer Docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A web browser to test and view the colour flipper. Google Chrome, Mozilla Firefox, Microsoft Edge, or Safari are suitable choices.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 1-Creating Our Files
&lt;/h2&gt;

&lt;p&gt;To get started with creating our colour flipper, we first need to open our code editor and create 3 files index.html, index.css, and index.js.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2- Adding the HTML Code
&lt;/h2&gt;

&lt;p&gt;Inside our HTML file, we will add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;color flipper&amp;lt;/title&amp;gt;
    &amp;lt;!-- css --&amp;gt;
    &amp;lt;link rel="stylesheet" href="index.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

    &amp;lt;!-- HEADER  --&amp;gt;
    &amp;lt;header&amp;gt;
        &amp;lt;h1&amp;gt;Color Flipper&amp;lt;/h1&amp;gt;
    &amp;lt;/header&amp;gt;
    &amp;lt;!-- MAIN  --&amp;gt;
    &amp;lt;main&amp;gt;

        &amp;lt;div class="container"&amp;gt;
            &amp;lt;h2&amp;gt;Background Color &amp;lt;span id="value"&amp;gt;#0a0a23&amp;lt;/span&amp;gt;&amp;lt;/h2&amp;gt;

            &amp;lt;div class="button-container"&amp;gt;  &amp;lt;!--div containing button--&amp;gt;
            &amp;lt;button id="btn"&amp;gt;click me&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;

    &amp;lt;!-- Javascript --&amp;gt;
    &amp;lt;script src="index.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me explain the above code in our HTML file.&lt;br&gt;
The file contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Firstly, we have linked our HTML to our CSS for styling.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;br&gt;
&lt;code&gt;&amp;lt;link rel="stylesheet" href="index.css"&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Secondly, we added &lt;strong&gt;script tag&lt;/strong&gt; to link to the javascript file&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;script src="index.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;strong&gt;header&lt;/strong&gt; with the Color Flipper text. This explains what our project is about.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We also created a div container in our main tag that contains an &lt;strong&gt;h2&lt;/strong&gt; text Background Color and &lt;strong&gt;span&lt;/strong&gt; text of the current body background colour. Also, we have a div that contains a button that changes the body background color style when clicked.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: The span and the button tags have unique IDs, enabling us to target them with javascript.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Open your browser and you will see the HTML Output:

See the Pen &lt;a href="https://codepen.io/mbuguadev/pen/NWEXwLm"&gt;
Untitled&lt;/a&gt; by Dennis Mbugua (&lt;a href="https://codepen.io/mbuguadev"&gt;@mbuguadev&lt;/a&gt;)
on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;## Step 3-Adding  CSS code&lt;br&gt;
So, let us add our CSS code to the &lt;strong&gt;index.css&lt;/strong&gt; file :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* css reset */
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* general styling */

body{
   min-height: 100vh;/* set body min-height to at least 100% viewports height*/
    background-color: #0a0a23;
    color: #fff;
    text-align: centre;

} 

/* --------------  CONTAINER STYLES*
-------------------*/
.container{
    text-align: center;
}
main{
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.container h2{
    margin-bottom: 2rem;
    background-color: coral;
    padding: 1rem;
    border-radius: 10px;
}

/* button styling */
#btn{
    font-family: sans-serif;
    text-transform: uppercase;
    background: transparent;
    color: #fff;
    letter-spacing: 1.2;
    display: inline-block;
    font-weight: 700;
    transition:0.3s;
    border: 2px solid coral;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    font-size: 1rem;
    padding: 0.75rem 1.25rem;
}
#btn:hover,:focus{
    opacity: 0.7;
    background-color: #999;
    cursor: pointer;
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the &lt;strong&gt;&lt;em&gt;Css code&lt;/em&gt;&lt;/strong&gt; above, we have done the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reset the default styles using the &lt;em&gt;*&lt;/em&gt; universal selector.&lt;/li&gt;
&lt;li&gt;Set the body styles to a min- height to 100% of the viewport height.&lt;/li&gt;
&lt;li&gt;Center the main content using CSS Grid.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Added styles to the button with ID of "btn" and hover effects. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;ul&gt;
&lt;li&gt;After adding the css code, save and refresh the browser for result.
Now the page looks like this with CSS styles

See the Pen &lt;a href="https://codepen.io/mbuguadev/pen/NWEXwLm"&gt;
Untitled&lt;/a&gt; by Dennis Mbugua (&lt;a href="https://codepen.io/mbuguadev"&gt;@mbuguadev&lt;/a&gt;)
on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;## Step 4-Adding Functionality with Javascript&lt;/p&gt;

&lt;p&gt;Now that our HTML and CSS codes are set,  it is time write our javascript code.We are going to add functionality to the color flipper.&lt;/p&gt;

&lt;p&gt;In our javascript code, we will first need to do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an array that contains the HEX color characters.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;let  hexCharacters = [0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"];&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;HEX colors values contains combination of 6 characters from the set of 0-9 and A-F. We have stored the characters in &lt;strong&gt;hexCharacters&lt;/strong&gt; variable.&lt;/p&gt;

&lt;p&gt;Select our &lt;strong&gt;span&lt;/strong&gt; and &lt;strong&gt;button&lt;/strong&gt; elements using their respective ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const spanValue = document.getElementById('value');
const clickButton = document.getElementById('btn');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have used  the Javascript  in built method &lt;code&gt;document.getElementById&lt;/code&gt; that helps to retrieve a reference to a HTML element using the element's ID.&lt;br&gt;
   The &lt;strong&gt;spanValue&lt;/strong&gt; and &lt;strong&gt;clickButton&lt;/strong&gt; variables stores references to HTML elements with the IDs 'value' and 'btn', respectively.&lt;/p&gt;

&lt;p&gt;Now that we are done creating variables, let us add  the functions to our javascript code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // create an event listener to button
clickButton.addEventListener('click', function(){
    getRandomCharacter(); // call the getRandomCharacter function on click

});

// function to generate HEX value characters
function getRandomCharacter(){

    let hexColorCharacters = "#";  //intial value of of our color value

    for(let i=0; i&amp;lt;6;i++){
        hexColorCharacters +=hexCharacters[generateRandomNumber()];  
    }

    spanValue.textContent = hexColorCharacters; // set the span text content to current background color value

    /*set body background color to  hexColorCharacters;
    it contains 6 random characters generated from hexCharacters array */
    document.body.style.backgroundColor = hexColorCharacters;
}

/*function that generates random numbers
//generates numbers between 0 and 16 */

function generateRandomNumber(){
    return Math.floor(Math.random() * hexCharacters.length);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what we have done in the above javascript code:&lt;/p&gt;

&lt;p&gt;*Step I:&lt;br&gt;
we have created an event listener to our button with the ID "btn".&lt;br&gt;
We want an event( in this case a click event) to happen when the button is clicked.&lt;br&gt;
When the button is clicked, it triggers the function specified.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step II:&lt;br&gt;
  The event listener triggers anonymous function(function without a name), when button is clicked.&lt;br&gt;
  Now, inside this anonymous function, we call the **getRandomCharacter()&lt;/em&gt;*&lt;br&gt;
  function&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step III: What is happening inside the **getRandomCharacter()&lt;/em&gt;* function:&lt;/p&gt;

&lt;p&gt;In this function, we have a variable  &lt;strong&gt;hexColorCharacters&lt;/strong&gt; which  starts with "#" (a valid starting character for HEX colors). &lt;br&gt;
  when the loop runs,  it appends  a random HEX characters from the &lt;strong&gt;hexCharacters&lt;/strong&gt; array, forming a complete 6-character HEX color code.&lt;/p&gt;

&lt;p&gt;In the for loop, we generate a random HEX color value by selecting random characters from a list of valid HEX characters, which includes numbers 0-9 and letters A-F(as we said above). The loop runs six times, with each iteration appending a new random character to the hexColorCharacters variable, initially set  to "#" as the valid HEX color prefix. After completing the loop, the &lt;strong&gt;hexColorCharacters&lt;/strong&gt; holds a complete 6-character random HEX color value. For example("#4B32BD");&lt;/p&gt;

&lt;p&gt;The function also:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Sets  this &lt;strong&gt;hexColorCharacters&lt;/strong&gt;  as the content of the span using &lt;strong&gt;textContent&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Sets the background color of the webpage body &lt;strong&gt;(document.body.style.backgroundColor)&lt;/strong&gt; to the generated HEX color.
&lt;em&gt;Step IV
The function **generateRandomNumber()&lt;/em&gt;* utilizes the &lt;strong&gt;Math.random()&lt;/strong&gt;
and &lt;strong&gt;Math.floor()&lt;/strong&gt; mathods to generate random numbers between 0 and 15 &lt;strong&gt;(hexCharacters.length - 1)&lt;/strong&gt;.
We noe use the function to index into the &lt;strong&gt;hexCharacters&lt;/strong&gt; array, and pick a random HEX character.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the complete  javascript code in our &lt;strong&gt;index.js&lt;/strong&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//  create a variable to store HEX character combination
let  hexCharacters = [0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"];


// Select span and button element using their ID values

const spanValue = document.getElementById('value');
const clickButton = document.getElementById('btn');


// create an event listener to button
clickButton.addEventListener('click', function(){
    getRandomCharacter(); // call the getRandomCharacter function on click

});

// function to generate HEX value characters
function getRandomCharacter(){

    let hexColorCharacters = "#";  //intial value of of our color value

    for(let i=0; i&amp;lt;6;i++){
        hexColorCharacters +=hexCharacters[generateRandomNumber()];  
    }

    spanValue.textContent = hexColorCharacters; // set the span text content to current background color value

    /*set body background color to  hexColorCharacters;
    it contains 6 random characters generated from hexCharacters array */
    document.body.style.backgroundColor = hexColorCharacters;
}

/*function that generates random numbers
//generates numbers between 0 and 16 */

function generateRandomNumber(){
    return Math.floor(Math.random() * hexCharacters.length);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Give yourself a part on the back for the great work. Now that we have completed our code, click the button to start playing with the color flipper.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;See the result in  codepen&lt;/strong&gt;&lt;br&gt;
  &lt;br&gt;
  See the Pen &lt;a href="https://codepen.io/mbuguadev/pen/NWEXwLm"&gt;&lt;br&gt;
  Untitled&lt;/a&gt; by Dennis Mbugua (&lt;a href="https://codepen.io/mbuguadev"&gt;@mbuguadev&lt;/a&gt;)&lt;br&gt;
  on &lt;a href="https://codepen.io"&gt;CodePen&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

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

&lt;p&gt;You have successfully created a color flipper that changes the background of our page on the click of a button.&lt;br&gt;
With this Javascript project, you have learnt how to generate random numbers using &lt;strong&gt;Math.random()&lt;/strong&gt; and &lt;strong&gt;Math.floor()&lt;/strong&gt; methods. Along the way, you have learnt Javascript DOM manipulation and how to write reusable code with Javascript functions. It is my hope that you will use these concepts in your next project.&lt;/p&gt;

&lt;p&gt;Let me know how you felt about this on  &lt;a href="https://twitter.com/mbugua_dennis33"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Written by &lt;strong&gt;Dennis Mbugua&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>Understand let, var and const keywords</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Sun, 09 Jul 2023 08:54:32 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/understand-let-var-and-const-keywords-325m</link>
      <guid>https://dev.to/mbuguadennis/understand-let-var-and-const-keywords-325m</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;The best measure for growth in any area of life is the ability to embrace change. Everyone feels productive when trying new things, and becoming adventurous gives that sense of confidence.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now in the life of any software developer, change is inevitable. Often, it is hard. Why? Because technology is fast-evolving, new languages and updates are constantly released. Being a developer is signing in to becoming a life-long student.&lt;/p&gt;

&lt;p&gt;This article is neither meant for motivational speaking nor change discussion. We will explore ECMAScript2015,  known as ES6.  ES6  is the ECMAScript language specification standard's 6th and most significant edition. &lt;br&gt;
With ES6, you can write Javascript with simple code, increasing readability.&lt;/p&gt;
&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;Before getting with this article, you need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Know Javascript Basics. To get started with Javascript, &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics"&gt;Mozzila Developers&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Understand how to use the DevTools console to run Javascript code. This video will help you get started. &lt;a href="https://www.youtube.com/watch?v=RLCpvCTiDRo"&gt;Console Logging Javascript&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Be willing to learn and practice.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; Keywords
&lt;/h2&gt;

&lt;p&gt;Both &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt;keywords are used in declaring variables. &lt;code&gt;let&lt;/code&gt;and &lt;code&gt;var&lt;/code&gt;differ in the scope of the variables they create.&lt;br&gt;
When you declare a variable with the &lt;code&gt;var&lt;/code&gt;keyword, it is declared globally. The &lt;code&gt;var&lt;/code&gt;keyword, however, is declared locally if inside a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myName = "Dennis"; // declared globally 
console.log(myName) //Output- Dennis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above &lt;code&gt;myName&lt;/code&gt;variable is declared globally, hence, can be accessed anywhere in your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CASE 1

function firstName(){
    var myName = "Dennis"; //declared locally
    return myName;
} 
console.log(firstName()); //Output  -Dennis
CASE 2
function secondName(){
    return myName;
}
console.log(secondName()); // _Output a Uncaught ReferenceError: myName is not defined_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me explain what the  above code does:&lt;br&gt;
CASE 1&lt;br&gt;
We have declared the &lt;code&gt;myName&lt;/code&gt;variable inside a function &lt;code&gt;firstName&lt;/code&gt;, right? then we return the &lt;code&gt;myName&lt;/code&gt;variable.&lt;br&gt;
when you call the function, the &lt;code&gt;myName&lt;/code&gt;variable can be seen by the function hence the console logs &lt;code&gt;Dennis&lt;/code&gt;.&lt;br&gt;
CASE 2&lt;br&gt;
We have a function &lt;code&gt;secondName&lt;/code&gt;that returns the &lt;code&gt;myName&lt;/code&gt;variable which is only locally available in the &lt;code&gt;firstName&lt;/code&gt;function. When you call the &lt;code&gt;secondName&lt;/code&gt;function, the console logs an error.&lt;br&gt;
However, changing the &lt;code&gt;myName&lt;/code&gt;variable to global, the &lt;code&gt;secondName&lt;/code&gt;function should return &lt;code&gt;Dennis&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; Keyword&lt;br&gt;
When you declare a variable with the let keyword inside a block, statement, or expression, its scope is constrained to that block, statement, or expression.&lt;/p&gt;

&lt;p&gt;In JavaScript, a block is a set of zero or more statements grouped inside a pair of curly braces { }.&lt;br&gt;
A block can contain any valid JavaScript statement, including variable declarations, loops, conditionals, function declarations, and expressions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variable declaration inside a block
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  let x = 10;
  console.log(x); // Output: 10
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt; Variable declaration as a statement
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let y = 5;
console.log(y); // Output: 5

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

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt; Variable declaration as an expression
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let z = (a = 2, b = 3, a + b);
console.log(z); // Output: 5

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

&lt;/div&gt;


&lt;p&gt;Here's an example that demonstrates how the let keyword creates variables with limited scope:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function exampleFunction() {
  let x = 10;

  if (true) {
    let y = 20;
    console.log(x); // Output: 10
    console.log(y); // Output: 20
  }

  console.log(x); // Output: 10
  console.log(y); // Uncaught ReferenceError: y is not defined
}

exampleFunction();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the exampleFunction function contains two let declarations:&lt;br&gt;
 &lt;code&gt;let x = 10, and let y = 20;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside the if statement block, both &lt;code&gt;x&lt;/code&gt;and &lt;code&gt;y&lt;/code&gt;are accessible because the &lt;code&gt;let&lt;/code&gt;keyword creates variables with block scope. This means that the variables declared with &lt;code&gt;let&lt;/code&gt;are only accessible within the block where they are defined or any nested blocks.&lt;/p&gt;

&lt;p&gt;However, outside the &lt;code&gt;if&lt;/code&gt;statement block, &lt;code&gt;y&lt;/code&gt;is no longer accessible. When we attempt to access &lt;code&gt;y&lt;/code&gt;after the &lt;code&gt;if&lt;/code&gt;statement, an &lt;code&gt;Uncaught ReferenceError&lt;/code&gt; is thrown because&lt;code&gt;y&lt;/code&gt; is not defined in that scope.&lt;/p&gt;

&lt;p&gt;On the other hand, &lt;code&gt;x&lt;/code&gt; is accessible both inside and outside the if statement block because it is declared in the outer scope of the function.&lt;/p&gt;
&lt;h2&gt;
  
  
  Mutate array declared with &lt;code&gt;const&lt;/code&gt;keyword
&lt;/h2&gt;

&lt;p&gt;The const keyword is applicable in many use cases in Modern Javascript.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Some developers prefer to use the &lt;code&gt;const&lt;/code&gt;keyword throughout. The developers, who use the &lt;code&gt;const&lt;/code&gt; keyword however, may use the &lt;code&gt;let&lt;/code&gt;keyword when they need to reassign a value later.&lt;/p&gt;

&lt;p&gt;Variables declared with the &lt;code&gt;const&lt;/code&gt;keyword are&lt;code&gt;read-only&lt;/code&gt;. However, it is important to note objects(including arrays and functions) assigned to a variable using const are still mutable.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = [2,3,4,5,6];
 arr = [4,5,6,7];
arr[2] = 50;
console.log(arr);

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;arr = [4,5,6,7]&lt;/code&gt;will result in an error. when you comment on the line, the console.log will display &lt;code&gt;[2,3,50,5,6]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;From the above example, you can mutate objects, and the&lt;code&gt;arr&lt;/code&gt; variable still points to the altered array. Like all arrays, the array elements in &lt;code&gt;arr&lt;/code&gt;are mutable, but because &lt;code&gt;const&lt;/code&gt;was used, you cannot use the variable identifier &lt;code&gt;arr&lt;/code&gt;to point to a different array using the assignment operator.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to prevent Object mutation
&lt;/h2&gt;

&lt;p&gt;From the previous example, &lt;code&gt;const&lt;/code&gt; keywords do not protect your data from mutation.&lt;br&gt;
Javascript provides an &lt;code&gt;Object.freeze()&lt;/code&gt; function to prevent mutation. Any attempt to mutate data will throw an error if the script is running in strict mode.&lt;br&gt;
for example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myObject = {
name: "Dennis,
age:30
}
Object.freeze(myObject);
myObject.name = "John"
myObject.newproperty = "learning"
console.log(myObject);

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

&lt;/div&gt;



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

&lt;p&gt;Thanks for reading this article. &lt;br&gt;
You have learned to declare variables in Javascript using &lt;code&gt;let&lt;/code&gt;&lt;code&gt;const&lt;/code&gt;and &lt;code&gt;var&lt;/code&gt;keywords.&lt;br&gt;
Also, the article has helped you understand how the keywords create scopes in your code.&lt;/p&gt;

&lt;p&gt;This article was written by &lt;strong&gt;Dennis&lt;/strong&gt; &lt;strong&gt;Mbugua&lt;/strong&gt;.&lt;br&gt;
Follow me on Twitter &lt;a href="https://twitter.com/eikev_dennis"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to get started with Javascript- Part One</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Tue, 27 Jun 2023 13:38:36 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/how-to-get-started-with-javascript-part-one-246d</link>
      <guid>https://dev.to/mbuguadennis/how-to-get-started-with-javascript-part-one-246d</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Javascript is a scripting language you can use to create dynamic web pages. It is one of the core languages used along with HTML and CSS, and is supported by modern browsers.&lt;br&gt;
In this beginners series part one, we are going to learn the basics of javascript. Later on, we are going to be advance to even complex topics.&lt;br&gt;
By learning  and completing this series, you will write your first line of Javascript with absolute confidence.&lt;/p&gt;
&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;These tutorials do not require a prior javascript knowledge.However, you must have a basic understanding  the following;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML  and CSS. You can start by learning from &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/HTML"&gt;mdn docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic understanding of linking html file and javascript. Learning that takes few minutes &lt;a href="https://www.w3schools.com/tags/att_script_src.asp"&gt;at w3school&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, we are going to learn about:&lt;/p&gt;
&lt;h1&gt;
  
  
  Table of Contents
&lt;/h1&gt;

&lt;p&gt;1.Add comments in Javascript&lt;br&gt;
2.Declare Javascript Variables&lt;br&gt;
3.Assign one value of a variable to another&lt;br&gt;
4.Declaring string variables&lt;br&gt;
5.Understanding Uninitialized Variables&lt;br&gt;
6. Case sensitivity in Javascript variables&lt;br&gt;
7.Understand differences between &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; keyword &lt;br&gt;
8.Best practice&lt;br&gt;
9.Conclusion&lt;/p&gt;
&lt;h2&gt;
  
  
  Add comments in Javascript
&lt;/h2&gt;

&lt;p&gt;Comments in Javascript lines are lines which explain what the code does, and why a particular code was written in a certain way. Comments make  the code more readable.&lt;br&gt;
Another great use of comments is to remove code from execution when debugging scripts.&lt;br&gt;
The following are the two commonly used Javascript comments;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inline comment.&lt;/li&gt;
&lt;li&gt;- Multiline comment. &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;1. Inline comment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To create a single line comment in JavaScript, you place two slashes "//" in front of the code or text you wish to have the JavaScript interpreter ignore. When you place these two slashes, all text to the right of them will be ignored, until the next line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alert (“I have comments in my code”);
` //This is an inline comment`

&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code displays the following  alert message on the browser. &amp;gt;&lt;br&gt;
&lt;code&gt;I have comments in my code&lt;/code&gt;&lt;br&gt;
The second line is never executed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2. multiline  comment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inline comments are quite useful.However, it can be burdensome to disable long lines of code or insert long-winded comments. For larger comments, you can used multiline comments that begins with &lt;code&gt;/*&lt;/code&gt; and ends with &lt;code&gt;*/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br&gt;
alert(“I have multiline comments in my code”);&lt;br&gt;
/* This is multiline code&lt;br&gt;
This is multiline code&lt;br&gt;
This is multiline code&lt;br&gt;
This is multiline code&lt;br&gt;
This is multiline code&lt;br&gt;
This is multiline code&lt;br&gt;
*/&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above code displays the following  alert message on the browser.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;I have multiline comments in my code&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Declare Javascript Variables
&lt;/h2&gt;

&lt;p&gt;In computer science, data is anything meaningful to a computer. Javascript provides eight data types. You can learn about  javascript data types on (&lt;a href="https://www.w3schools.com/js/js_datatypes.asp"&gt;https://www.w3schools.com/js/js_datatypes.asp&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To store data in computers, you create a variable that points to the data rather than data itself.&lt;br&gt;
You declare a variable by putting either one of  the following keywords in front of the variable;&lt;br&gt;
&lt;code&gt;&lt;br&gt;
var&lt;br&gt;
let&lt;br&gt;
const&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For example, you can declare a variable named &lt;code&gt;myNumber&lt;/code&gt;  as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var  myNumber;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code creates  a variable called &lt;code&gt;myNumber&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Store values with assignment with assignment operator
&lt;/h3&gt;

&lt;p&gt;You can store a value in a variable using the assignment operator  &lt;code&gt;=&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var myNumber = 5 ;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code assigns the value 5 to  &lt;code&gt;*myNumber*&lt;/code&gt;;&lt;/p&gt;

&lt;h2&gt;
  
  
  Assign one value of a variable to another
&lt;/h2&gt;

&lt;p&gt;You can assign the value of a variable to another variable after assigning the value with the assignment operator.&lt;/p&gt;

&lt;p&gt;For example, in the above example, &lt;code&gt;myNumber&lt;/code&gt; variable can be assigned to another variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var myNumber = 5 ;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can declare another variable and assign it the value of myNumber.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var mySecondNumber = myNumber;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now  the variable mySecondNumber contains  the value of  myNumber . &lt;/p&gt;

&lt;h2&gt;
  
  
  Declaring string variables
&lt;/h2&gt;

&lt;p&gt;So far, we have been declaring number variables  in our examples.&lt;br&gt;
You can also declare variables as follows;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myName = “Dennis”;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;“Dennis”   is referred to as string literal. A string literal is a variable in javascript  containing 0 or more characters. &lt;br&gt;
String variables in javascript are enclosed with double quotes  “ ” or single quotes ‘ ‘.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Uninitialized Variables
&lt;/h2&gt;

&lt;p&gt;When Javascript variables are first  declared, they have a value of &lt;code&gt;undefined&lt;/code&gt;. If you do mathematical operations on undefined variables, you get a value of &lt;code&gt;NaN&lt;/code&gt;. If you concatenate two undefined strings, you get  a value of &lt;code&gt;undefined&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;For example, the following  variable has a value of undefined. The variable has been declared with no value assigned to it.&lt;br&gt;
&lt;code&gt;var mysum&lt;/code&gt;;&lt;/p&gt;

&lt;h2&gt;
  
  
  Case sensitivity in Javascript variables
&lt;/h2&gt;

&lt;p&gt;In JavaScript all variables and function names are case sensitive. This means that capitalization matters.&lt;br&gt;
&lt;code&gt;MYVAR&lt;/code&gt; is not the same as &lt;code&gt;MyVar&lt;/code&gt;nor myvar`. It is possible to have multiple distinct variables with the same name but different casing. It is strongly recommended that for the sake of clarity, you do not use this language feature.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best Practice
&lt;/h3&gt;

&lt;p&gt;Write variable names in JavaScript in camelCase. In camelCase, multi-word variable names have the first word in lowercase and the first letter of each subsequent word is capitalized.&lt;/p&gt;

&lt;p&gt;Example,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
var someVariable;&lt;br&gt;
var anotherVariableName;&lt;br&gt;
var thisVariableNameIsSoLong;&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand differences between &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; keyword
&lt;/h2&gt;

&lt;p&gt;One of the biggest challenges of using var keywords is that variables can be easily overwritten.&lt;br&gt;
For example&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
var name = “Dennis”;&lt;br&gt;
var  name = “David”;&lt;br&gt;
console.log(name);&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above code displays &lt;code&gt;David &lt;/code&gt; since &lt;code&gt;Dennis&lt;/code&gt; has been overwritten.&lt;/p&gt;

&lt;p&gt;In small applications, this does not pose a major challenge.However, as the codebase becomes bigger, then this is a big challenge.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;let keyword &lt;/code&gt; was introduced in Es6 ( a topic for another day)  to solve this exponential challenge. Variables declared with the &lt;code&gt;let keyword&lt;/code&gt; cannot be re-assigned.&lt;/p&gt;

&lt;p&gt;Replacing the following code with let keywords,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
let name = “Dennis”;&lt;br&gt;
let  name = “David”;&lt;br&gt;
console.log(name);&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
The following error is thrown in console;&lt;br&gt;
_Uncaught SyntaxError: Identifier 'myName' has already been declared _&lt;/p&gt;

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

&lt;p&gt;Javascript is used in creating  dynamic websites.The best way to get started with Javascript is to grasp the foundations and basics right front zero level to the most advanced level.&lt;br&gt;
In this article, you learned  what variables are, how to declare and initialize them in Javascript.You also learnt how to use &lt;strong&gt;camelCase&lt;/strong&gt; naming convention while working with Javascript variables. &lt;br&gt;
You can enhance your understanding of the covered concepts by learning  from &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics"&gt;Mozilla Developers Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Written by Dennis Mbugua.&lt;br&gt;
&lt;a href="https://twitter.com/eikev_dennis"&gt;Follow me on Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Beginners series learning Javascript</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Sun, 25 Jun 2023 10:11:27 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/beginners-series-learning-javascript-33a6</link>
      <guid>https://dev.to/mbuguadennis/beginners-series-learning-javascript-33a6</guid>
      <description>&lt;p&gt;Hi, my name is Dennis. I am a front-end web developer and a Technical writer.&lt;br&gt;
Are you getting started with learning javascript to power up your skills? if this is you, then you have found the right place to hold on to for a while. A journey of a thousand steps starts with a single step. It is even worthier when the journey is heading to the right direction. I will be creating a series of javascript tutorials from beginner level to advanced level. After completing this series, you will write javascript lines with confidence.&lt;br&gt;
Lets embark on this exciting journey of growth together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;This series do not require you to have previous knowledge with javascript. However, you should already have prior knowledge of working with HTML AND CSS. &lt;/p&gt;

&lt;h2&gt;
  
  
  Where to learn?
&lt;/h2&gt;

&lt;p&gt;I will be writing and publishing the articles here.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Written by Dennis Mbugua(eikev)&lt;/em&gt;&lt;br&gt;
 Follow me on &lt;a href="https://twitter.com/eikev_dennis"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Use of the Javascript keywords var, let, and const in a variable declaration</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Mon, 20 Mar 2023 05:31:36 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/use-of-the-javascript-keywords-var-let-and-const-in-a-variable-declaration-11j7</link>
      <guid>https://dev.to/mbuguadennis/use-of-the-javascript-keywords-var-let-and-const-in-a-variable-declaration-11j7</guid>
      <description>&lt;h1&gt;
  
  
  Pre-requisites
&lt;/h1&gt;

&lt;p&gt;This article is targeted at beginners who want to learn about keywords, var, let and const in variable declaration.&lt;br&gt;
Before diving into this article, make sure that you understand the &lt;br&gt;
&lt;strong&gt;camelCase&lt;/strong&gt; naming convention used in JavaScript. &lt;/p&gt;

&lt;p&gt;Data in computer science refers to everything that the computer can use to make sense of. &lt;code&gt;Undefined&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;Boolean&lt;/code&gt;, &lt;code&gt;text&lt;/code&gt;, &lt;code&gt;symbol&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, and &lt;code&gt;object&lt;/code&gt; are the eight distinct data types that JavaScript supports.&lt;br&gt;
For example, computers distinguish between numbers, such as &lt;code&gt;12&lt;/code&gt; and &lt;code&gt;strings&lt;/code&gt;, "123”, which are collections of characters.&lt;br&gt;
Also, computers can perform mathematical operations on numbers but not on strings.&lt;/p&gt;

&lt;p&gt;In this article, we are going to learn about:&lt;/p&gt;
&lt;h1&gt;
  
  
  Table of contents
&lt;/h1&gt;

&lt;p&gt;1.What is a variable?&lt;br&gt;
2.variable declaration using var&lt;br&gt;
3.Cons of using var keyword&lt;br&gt;
4.using keyword let&lt;br&gt;
5.Cons of using let keyword&lt;br&gt;
6.using keyword const&lt;br&gt;
7.Best practices of declaring variables&lt;br&gt;
8.conclusion&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a variable?
&lt;/h2&gt;

&lt;p&gt;A variable is a storage location that allows computers to store and dynamically manipulate data. Variables, do this by using a &lt;strong&gt;label&lt;/strong&gt; that points out to them rather than using data itself. Any of the eight data types highlighted above may be stored in a variable.&lt;br&gt;
Variables are similar to the x and y variables we use in mathematics. Therefore, variables are the simple name we use to refer to data. However, computer variables differ from mathematical variables in that they can store different values at different times. &lt;/p&gt;
&lt;h3&gt;
  
  
  Variable declaration using keyword &lt;code&gt;var&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;We tell JavaScript to create or &lt;code&gt;declare&lt;/code&gt; a variable by putting&lt;br&gt;
keyword &lt;code&gt;var&lt;/code&gt; in Infront of our desired variable name.&lt;br&gt;
&lt;strong&gt;for example, let us say we want a variable called myName&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;``&lt;code&gt;Put the&lt;/code&gt;var&lt;code&gt;keyword in Infront of your variable name like this,&lt;br&gt;
     var myName;&lt;br&gt;
var myName creates a variable called&lt;/code&gt;myName`. Variable names can be made up of numbers, letters, and $ or _, but may not contain spaces or begin with a number.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 for example 
var my Name -&amp;gt; !!!NOT ALLOWED
var 27myName -&amp;gt; !!!NOT ALLOWED

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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Cons of using the &lt;code&gt;var&lt;/code&gt; keyword
&lt;/h2&gt;

&lt;p&gt;One of the biggest problems of using the keyword &lt;code&gt;var&lt;/code&gt; is that you can easily overwrite variable declarations.&lt;br&gt;
&lt;code&gt;var name = "Dennis";&lt;br&gt;
var name = "Mbugua";&lt;br&gt;
console.log(name);&lt;/code&gt;&lt;br&gt;
In this above example, &lt;code&gt;name&lt;/code&gt; is originally declared as &lt;code&gt;Dennis’. The variable name&lt;/code&gt;Mbugua&lt;code&gt;overwrites&lt;/code&gt;Dennis&lt;code&gt;and the console logs out&lt;/code&gt;Mbugua`.&lt;br&gt;
In a small application, you might not run into this type of problem. But as your codebase becomes larger, you might accidentally overwrite a variable that you did not intend to. Because this behaviour does not throw an error, searching for and fixing bugs becomes more difficult.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using the &lt;code&gt;let&lt;/code&gt; keyword
&lt;/h2&gt;

&lt;p&gt;In Es6, a major update in JavaScript, the &lt;code&gt;let&lt;/code&gt; keyword was introduced, which helps to exponentially solve this &lt;code&gt;var&lt;/code&gt; problem.&lt;br&gt;
&lt;code&gt;let name = "Dennis";&lt;br&gt;
  let name = "Mbugua”;&lt;/code&gt;&lt;br&gt;
The error will be thrown onto the browser console. ‘let` keyword allows variables with the same name to be declared only once.&lt;/p&gt;
&lt;h2&gt;
  
  
  Advantages of using the &lt;code&gt;let&lt;/code&gt; keyword in a variable declaration
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;let&lt;/code&gt; keyword does not have major problems when compared with the &lt;code&gt;var&lt;/code&gt; keyword. As mentioned previously, let does not allow different variables to have the same name.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using the &lt;code&gt;const&lt;/code&gt; keyword in the variable declaration
&lt;/h2&gt;

&lt;p&gt;The keyword &lt;code&gt;let&lt;/code&gt; is not the only new way to declare variables. In &lt;code&gt;Es6&lt;/code&gt;, you can declare variables using the &lt;code&gt;const&lt;/code&gt; keyword.&lt;br&gt;
The &lt;code&gt;const&lt;/code&gt; keyword has all the properties that the &lt;code&gt;let&lt;/code&gt; keyword has, with a bonus that, variables declared using &lt;code&gt;const&lt;/code&gt; are &lt;code&gt;read only’. They are a constant&lt;/code&gt;value&lt;code&gt;. This means that variables declared with the&lt;/code&gt;const` keyword cannot be reassigned once declared.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 const met = "Cat";
    myPet = "Dog";


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

&lt;/div&gt;



&lt;p&gt;The above code will throw an error in the browser console because a &lt;code&gt;read only&lt;/code&gt; variable is reassigned to a new value. You should always name variables that you don’t want to reassign using the &lt;code&gt;const&lt;/code&gt; keyword. This helps when you accidentally attempt to reassign a variable that you want to remain unchanged.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best practices for declaring variables
&lt;/h3&gt;

&lt;p&gt;*&lt;em&gt;NOTE: *&lt;/em&gt; It is common for most developers to name immutable variables (which means can never be resigned once declared).&lt;br&gt;
for example, &lt;code&gt;const MYNAME&lt;/code&gt;.MYNAME variable is immutable and is in uppercase letters. This allows another person reading your code to identify the variable as read-only.&lt;/p&gt;

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

&lt;p&gt;In JavaScript, data is anything that can be manipulated dynamically. Computers allow data storage using variables.&lt;br&gt;
Variables are declared by putting either keywords &lt;code&gt;Var’, ‘let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; in Infront of your variable name. When declaring a variable, make sure you use the right keyword appropriately.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy coding&lt;/em&gt; Written by &lt;strong&gt;Dennis Mbugua&lt;/strong&gt;. &lt;strong&gt;Developer and Writer&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Follow me on Twitter&lt;/strong&gt; &lt;a href="https://twitter.com/mbugua_dev"&gt;link&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Follow me on GitHub&lt;/strong&gt; &lt;a href="https://github.com/MbuguaDennis"&gt;link&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>variables</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to comment in Javascript?</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Sun, 19 Mar 2023 12:54:01 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/how-to-comment-in-javascript-1c6c</link>
      <guid>https://dev.to/mbuguadennis/how-to-comment-in-javascript-1c6c</guid>
      <description>&lt;p&gt;Comments are lines of code that JavaScript will intentionally ignore. Comments are a great way to leave notes to yourself and to other people who will later need to figure out what that code does.&lt;br&gt;
There are two ways to write comments in javascript:&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;//&lt;/code&gt; will tell JavaScript to ignore the remainder of the text on the current line. This is an in-line comment:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// This is an inline comment in javascript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can make a multi-line comment beginning with /* and ending with */. This is a multi-line comment:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/* This is an multi-line comment */&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;As you write code, you should regularly add comments to clarify the function of parts of your code. Good commenting can help communicate the intent of your code—both for others and for your future self.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip:try commenting by writing each one of them today.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By &lt;strong&gt;Dennis Mbugua&lt;/strong&gt; Programmer and writer&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Accessibility Best Practices – What to Remember When Building Accessible Web Apps</title>
      <dc:creator>Dennis Ng'ang'a Mbugua</dc:creator>
      <pubDate>Tue, 14 Mar 2023 07:11:55 +0000</pubDate>
      <link>https://dev.to/mbuguadennis/accessibility-best-practices-what-to-remember-when-building-accessible-web-apps-51i5</link>
      <guid>https://dev.to/mbuguadennis/accessibility-best-practices-what-to-remember-when-building-accessible-web-apps-51i5</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Anyone should be able to use your websites and apps - both people with disabilities and those without. This will make your website accessible.&lt;br&gt;
Think about the last site you built, or your favorite site. Are you confident that anyone can use your site and perform the critical actions it requires? Have you considered folks with motor disabilities, visual disabilities, cognitive disabilities, and auditory disabilities?&lt;br&gt;
Accessibility is often left as an after-thought. When it is time to ship a feature, we do an accessibility test and find out that our site wasn't accessible and do a hacky fix.&lt;/p&gt;

&lt;p&gt;Making a site accessible is a huge undertaking. But if we keep accessibility in mind from the get-go, it makes it much easier to build an accessible web app.&lt;/p&gt;

&lt;p&gt;In this post, I will go over 5 things you can keep in mind WHILE building your app so you don't have to do a hacky slap together at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  5 things to remember for good accessibility
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Semantinc HTML&lt;/li&gt;
&lt;li&gt;Tabindex&lt;/li&gt;
&lt;li&gt;Aria attributes&lt;/li&gt;
&lt;li&gt;Role&lt;/li&gt;
&lt;li&gt;Keyboard navigation and screen readers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simply I term them as S.H.A.R.K&lt;br&gt;
let's go through each one of them and see how to make web accessible.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Semantic HTML?
&lt;/h2&gt;

&lt;p&gt;sing semantic HTML is important for accessibility. This is because assistive technologies such as screen readers are able to interpret what's on the page by parsing the HTML of the page. They enable users to take actions based on the elements.&lt;/p&gt;

&lt;p&gt;For example, if a screen reader encounters a &lt;code&gt;button&lt;/code&gt;, it signals to the user that they should click on it.&lt;/p&gt;

&lt;p&gt;Let's consider some use-cases of what can happen when you don't use semantic HTML:&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating buttons by using &lt;code&gt;div&lt;/code&gt; instead of &lt;code&gt;button&lt;/code&gt;:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;div&lt;/code&gt;s are container elements, so when a screen reader encounters a &lt;code&gt;div&lt;/code&gt;, it automatically thinks it is a presentational element.&lt;/p&gt;

&lt;p&gt;When a screen reader user encounters a &lt;code&gt;div&lt;/code&gt; that has content or children within it, the screen reader announces &lt;code&gt;role="group"&lt;/code&gt; and the user will completely miss that the div is interactive. So make sure you use the proper semantic element for its purpose. You get accessibility for free.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using CSS to fake headings instead of using&lt;code&gt;h1-6&lt;/code&gt; tags:
&lt;/h2&gt;

&lt;p&gt;Heading tags such as &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; let an assitive technology know that this is important text, and the screen reader will announce "Heading".&lt;br&gt;
When you use CSS to make a heading instead of using correct semantics, the significance of the text is lost to a screen reader.&lt;/p&gt;

&lt;p&gt;So just make sure to use semantic HTML whenever possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Tabindex?
&lt;/h2&gt;

&lt;p&gt;Adding a &lt;code&gt;tabindex&lt;/code&gt; makes interactive elements keyboard-navigable. When you add &lt;code&gt;tabindex&lt;/code&gt; to an element, a user is able to navigate to it using only their keyboard and/or assitive technologies.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You use a tabindex of &lt;code&gt;0&lt;/code&gt; to set focus to an element in the default tabbing order, &lt;/li&gt;
&lt;li&gt; You use a tabindex of &lt;code&gt;-1&lt;/code&gt; to programmatically focus an element using JavaScript.&lt;/li&gt;
&lt;li&gt; Do not assign a value of &amp;gt; 1 to tabindex.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A word of caution though - you should only add &lt;code&gt;tabindex&lt;/code&gt; to interactive elements. It is not a good practie to add tabindex to elements such as &lt;code&gt;div&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead of adding &lt;code&gt;tabindex&lt;/code&gt; in that case, use a semantic element, such as a &lt;code&gt;button&lt;/code&gt; since semantic elements already are tabbable and do not need an additional &lt;code&gt;tabindex&lt;/code&gt; value.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are ARIA attributes?
&lt;/h2&gt;

&lt;p&gt;Aria attributes such as &lt;code&gt;aria-checked&lt;/code&gt;, &lt;code&gt;aria-label&lt;/code&gt; give additional information to assistive technologies.&lt;br&gt;
Aria attributes are a set of HTML attributes that you use to provide additional information about the purpose and state of elements on a web page. These attributes are especially beneficial to assistive technologies to provide more context and better navigation for users.&lt;br&gt;
Some common aria-attributes include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;aria-label&lt;/code&gt;: used to provide a label or name for an element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aria-hidden&lt;/code&gt;: used to indicate that an element should be hidden from assistive technologies. This can be useful for elements that are used for layout purposes but are not relevant to the content of the page.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aria-describedby&lt;/code&gt;: used to associate an element with a description, which helps to provide context of an element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aria-live&lt;/code&gt;: used to indicate that an element's content may change dynamically, and that assistive technologies should pay attention to changes in the element's content.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can use these attributes in combination with each other and with standard HTML attributes to create more accessible and user-friendly web content.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the &lt;code&gt;aria-role&lt;/code&gt; attribute?
&lt;/h2&gt;

&lt;p&gt;For example, if you are building a grid component with the help of CSS and divs, you can use &lt;code&gt;role="grid"&lt;/code&gt; to let assistive technologies know about the semantics of the component.&lt;/p&gt;

&lt;p&gt;Some common &lt;code&gt;aria-roles&lt;/code&gt; include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;button&lt;/code&gt;: used to indicate that an element should be treated as a button.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;alert&lt;/code&gt;: used to indicate that an element is an alertbox.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;presentation&lt;/code&gt;: used to indicate that an element is only presentational.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is important to exercise caution with &lt;code&gt;aria-role&lt;/code&gt;. Remember to not overdo it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to handle keyboard navigation and screen readers
&lt;/h2&gt;

&lt;p&gt;Many users with motor disabilities rely on their keyboard and assitive technologies to navigate the web. So it's critical that every component be navigable using a keyboard and screen reader.&lt;br&gt;
You can test keyboard accessibility by navigating a site using only your keyboard. Here are some common keys:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;tab key&lt;/code&gt; to navigate to different sections of the site.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;spacebar&lt;/code&gt; to select elements, such as a checkbox.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;enter&lt;/code&gt; to press buttons.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While testing keyboard navigation, make sure you think about the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Focus remains visible: Ensure that you can clearly see which element is being focused on the page. Focus should always remain visible.&lt;/li&gt;
&lt;li&gt;Tab order: When tabbing through sections, the order of tabbing should follow the natural flow and logical structure of the website. It should not jump back and forth between sections.&lt;/li&gt;
&lt;li&gt;Keyboard traps: Ensure that when navigating with the keyboard, the focus doesn't get trapped on an element. For example, this could happen when a modal is opened, or the focus is navigated to a widget, such as calendar or emoji picker. Ensure that when you select an element in the widget, you are able to navigate back to the site.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;Overall, testing for accessibility during development is an important part of the process that can help to create more usable and accessible software for all users. Testing for accessibility early helps to provide a great user experience for everyone. Happy coding!&lt;/p&gt;

&lt;p&gt;Regards, Dennis Mbugua&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
      <category>accessiblity</category>
    </item>
  </channel>
</rss>
