<?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: Joseph Kilatya</title>
    <description>The latest articles on DEV Community by Joseph Kilatya (@kyule64).</description>
    <link>https://dev.to/kyule64</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%2F622332%2Fb685f362-1aaa-4a01-973e-c02cdb72f1ac.png</url>
      <title>DEV Community: Joseph Kilatya</title>
      <link>https://dev.to/kyule64</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kyule64"/>
    <language>en</language>
    <item>
      <title>Introduction to Data Structures and Algorithms with Modern Javascript.</title>
      <dc:creator>Joseph Kilatya</dc:creator>
      <pubDate>Mon, 21 Feb 2022 17:38:43 +0000</pubDate>
      <link>https://dev.to/kyule64/introduction-to-data-structures-and-algorithms-with-modern-javascript-2gp6</link>
      <guid>https://dev.to/kyule64/introduction-to-data-structures-and-algorithms-with-modern-javascript-2gp6</guid>
      <description>&lt;p&gt;A data structure is a particular way of organizing and storing data in a computer so that it can be accessed and modified efficiently. &lt;br&gt;
More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.&lt;br&gt;
There is huge concept behind data structures and algorithms. Therefore we are going to check few but key concepts in this sector.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arrays&lt;/strong&gt;&lt;br&gt;
In JavaScript, array is a single variable that is used to store different elements. It is often used when we want to store list of elements and access them by a single variable. In JavaScript therefore array is a single variable that stores multiple elements.&lt;br&gt;
Array syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var Array = [ ]; // method 1 
var Array = new Array(); // method 2 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sample code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//method 1
// array with string elements
var myArray = ['cat','dog','goat','cow']; 

// array with integer elememts
var myArray = [1,2,3,4,5,6]; 


//method 2
 // array with string elements
var myArray = new Array('cat','dog','goat','cow');

//array with integer elements
var myArray2 = new Array(1,2,3,4,5,6); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first element in an array has &lt;code&gt;index 0&lt;/code&gt; while the last element has &lt;code&gt;index n-1&lt;/code&gt;&lt;br&gt;
You can also check different array methods in javascript &lt;a href="https://www.w3schools.com/js/js_array_methods.asp"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A stack is a data structure that holds a list of elements. A stack works based on the LIFO principle i.e., Last In, First out, meaning that the most recently added element is the first one to remove.&lt;br&gt;
A good analogy to explain this is using books placed on top of each other. The last book to be added on top is the first one you can access. The first book(bottom book) will be accessed last.&lt;br&gt;
Stack methods in Javascript;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;push()&lt;/code&gt; method : allows you to add one or more elements to the end of the array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;pop()&lt;/code&gt; method : removes the element at the end of the array and returns the element to the caller. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sample code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let stack = [];

stack.push(1);
console.log(stack); // [1]

stack.push(2);
console.log(stack); // [1,2]

stack.push(3);
console.log(stack); // [1,2,3]

stack.push(4);
console.log(stack); // [1,2,3,4]

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linked lists&lt;/strong&gt;&lt;br&gt;
A linked list is a linear data structure that represents a collection of elements, where each element points to the next one. The first element in the linked list is the head and the last element is the tail.&lt;/p&gt;

&lt;p&gt;Each element of a linked list data structure must have the following properties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;value&lt;/code&gt;:The value of the element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;next&lt;/code&gt;: A pointer to the next element in the linked list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The main properties of a linked list data structure are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;size&lt;/code&gt;: The number of elements in the linked list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;head&lt;/code&gt;: The first element in the linked list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tail&lt;/code&gt;: The last element in the linked list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main operations of a linked list data structure are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;insertAt&lt;/code&gt;: Inserts an element at the specific index.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;removeAt&lt;/code&gt;: Removes the element at the specific index.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;getAt&lt;/code&gt;: Retrieves the element at the specific index&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;clear&lt;/code&gt;: Empties the linked list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reverse&lt;/code&gt;: Reverses the order of elements in the linked list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of a linked list 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 list = {
    head: {
        value: 6
        next: {
            value: 10                                             
            next: {
                value: 12
                next: {
                    value: 3
                    next: null  
                    }
                }
            }
        }
    }
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Queue&lt;/strong&gt;&lt;br&gt;
A queue is a data structure that follows First In First Out (FIFO) principle. The element that is added first is accessed at first. The last element to be added is therefore accessed at last.&lt;/p&gt;

&lt;p&gt;Example code of queue in Javascript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Queue {
    constructor() {
        this.items = [];
    }

    // add element to the queue
    enqueue(element) {
        return this.items.push(element);
    }
    // view the last element
    peek() {
        return this.items[this.items.length - 1];
    }
}
let queue = new Queue();

queue.enqueue(1);

queue.enqueue(2);

queue.enqueue(4);

queue.enqueue(8);

console.log(queue.items);

console.log(queue.peek());

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
So where can we how can we apply data structures in our programming journey.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Search − Algorithm to search an item in a data structure.&lt;/li&gt;
&lt;li&gt;Sort − Algorithm to sort items in a certain order.&lt;/li&gt;
&lt;li&gt;Insert − Algorithm to insert item in a data structure.&lt;/li&gt;
&lt;li&gt;Update − Algorithm to update an existing item in a data structure. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The topic on Javascript data structures and algorithms is very broad and wide. You can check on other resources out there to learn more.&lt;/p&gt;

&lt;p&gt;Happy Coding.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Javascript 101: Introduction To Modern Javacript</title>
      <dc:creator>Joseph Kilatya</dc:creator>
      <pubDate>Mon, 14 Feb 2022 20:43:55 +0000</pubDate>
      <link>https://dev.to/kyule64/javascript-101-introduction-to-modern-javacript-210c</link>
      <guid>https://dev.to/kyule64/javascript-101-introduction-to-modern-javacript-210c</guid>
      <description>&lt;p&gt;Javascript is client side scripting language in web development to make websites more interactive to their users. It is an interpreted language unlike other progamming languages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Brief Javascript History&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript was created at Netscape Communications by Brendan Eich in 1995.Initially known as LiveScript, Netscape changed the name to JavaScript so they could position it as a companion for the Java language.&lt;br&gt;
JavaScript is in no way related to the Java programming language. .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements to get you started&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A computer&lt;/li&gt;
&lt;li&gt;A web browser&lt;/li&gt;
&lt;li&gt;A text editor of your choice(I prefer using VSCode&lt;a href="https://code.visualstudio.com/download"&gt;&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Good internet.&lt;/li&gt;
&lt;li&gt;Motive.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Javascript syntax
&lt;/h2&gt;

&lt;p&gt;The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.&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;script ...&amp;gt;
   JavaScript code
&amp;lt;/script&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The script tag takes two important attributes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;language&lt;/strong&gt; - specifies what scripting language you are using.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;type&lt;/strong&gt; -  indicate the scripting language in use and its value should be set to "text/javascript".
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script language = "javascript" type = "text/javascript"&amp;gt;
   JavaScript code
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;** Your first 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;&amp;lt;html&amp;gt;
   &amp;lt;body&amp;gt;   
      &amp;lt;script language = "javascript" type = "text/javascript"&amp;gt;
         &amp;lt;!--
            document.write("Hello World!")
         //--&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;Javascript is a free format language , that is , it  ignores space, tabs and line breaks.&lt;/p&gt;

&lt;p&gt;semicolons in Javascript are optional. It is though a good practice to use them 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;&amp;lt;script language = "javascript" type = "text/javascript"&amp;gt;
   &amp;lt;!--
//codes lines without semicolons
      var1 = 10
      var2 = 20
// codes lines with semicolons
      var3 = 15; var4 = 25;
   //--&amp;gt;
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Comments in JS&lt;/strong&gt;&lt;br&gt;
Comments are crucial in any programming language.They make code more readable and leave remarks in our code.&lt;/p&gt;

&lt;p&gt;Single line Comments&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// This is the first comment
// This is the second comment
// I am a single line comment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiline comments&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* This is a multiline comment
Multiline comments can take multiple lines
JavaScript is the language of the web
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Javascript Placement
&lt;/h2&gt;

&lt;p&gt;There is a flexibility given to include JavaScript code anywhere in an HTML&lt;br&gt;
document. However the most preferred ways to include JavaScript in an HTML&lt;br&gt;
file are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Script in ... section.&lt;/li&gt;
&lt;li&gt;Script in ... section.&lt;/li&gt;
&lt;li&gt;Script in ... and ... sections.&lt;/li&gt;
&lt;li&gt;Script in an external file and then include in ... section.
The first three are written between the script tags.
&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;script language = "javascript" type = "text/javascript"&amp;gt;
   JavaScript code
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Script in an external file and then include in &lt;/p&gt;... section.&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;script type="text/javascript" src="filename.js" &amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
.......
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Variables in Js
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Variable declaration&lt;/strong&gt;&lt;br&gt;
We can declare variables using three methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var age = 20;
    // var values can change

let name = 'Joshua';
    // same as var
const gravity = 10;
   //used to declare constant values e.g gravity as in above 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NB&lt;/strong&gt; It is a good practice to use &lt;code&gt;let&lt;/code&gt; rather than &lt;code&gt;var&lt;/code&gt; in variable declarations as it is more secure method.&lt;br&gt;
Variables are containers of data.. &lt;br&gt;
In JS variable there are diffrent kinds of data types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Numbers&lt;/strong&gt;&lt;br&gt;
 integers(whole numbers)&lt;br&gt;
&lt;code&gt;Var num1 = 10;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;float-point number(numbers with fractions)&lt;br&gt;
&lt;code&gt;var num2 = 15.69;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Strings&lt;/strong&gt;&lt;br&gt;
A collections of more than one characters between two single quotes, double quotes, or backticks.&lt;br&gt;
&lt;code&gt;var sayHi = "Hello, World";&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Booleans&lt;/strong&gt;&lt;br&gt;
A boolean value is either True or False while boolean data types are either true or false. They return a true  or false value.&lt;br&gt;
&lt;code&gt;true // if the light is on, the value is true&lt;br&gt;
false // if the light is off, the value is false&lt;/code&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Undefined&lt;/strong&gt;&lt;br&gt;
In JavaScript, if we don't assign a value to a variable, the value is undefined. In addition to that, if a function is not returning anything, it returns undefined.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;script&amp;gt;
var firstName;
document.write(firstName) // undefined, because it is not assigned to a value yet
&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
.......
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Null&lt;/strong&gt; 
Null in JavaScript means an empty value.
&lt;code&gt;var emptyValue = null;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Variable naming rules&lt;/strong&gt;&lt;br&gt;
 In Javascript we have rules that are used when naming variables. Most of the rules apply in other programming languages.&lt;br&gt;
A valid JavaScript variable name must follow the following rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A JavaScript variable name should not begin with a number.&lt;/li&gt;
&lt;li&gt;A JavaScript variable name does not allow special characters except dollar sign and underscore.&lt;/li&gt;
&lt;li&gt;A JavaScript variable name follows a camelCase convention.&lt;/li&gt;
&lt;li&gt;A JavaScript variable name should not have space between words.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following are examples of valid JavaScript variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firstName
lastName
country
city
capitalCity
age
isMarried

first_name
last_name
is_married
capital_city

num1
num_1
_num_1
$num1
year2020
year_2020
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example of invalid Variable names&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  first-name
  1_num
  num_#_1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Javascript is an awesome scripting language that can be used in almost all fields in technology especially in web development.It is easy to learn and user-friendly. Happy coding!&lt;br&gt;
Please drop a comment if you liked this blog or if there is anything you need clarification about. Thank you.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
