<?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: John Katua</title>
    <description>The latest articles on DEV Community by John Katua (@johnkatua).</description>
    <link>https://dev.to/johnkatua</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F814126%2F5307ce75-e793-4fcc-b485-955faa96f57d.jpeg</url>
      <title>DEV Community: John Katua</title>
      <link>https://dev.to/johnkatua</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johnkatua"/>
    <language>en</language>
    <item>
      <title>Modern Javascript for everyone: Mastering modern Javascript the right way.</title>
      <dc:creator>John Katua</dc:creator>
      <pubDate>Fri, 04 Mar 2022 20:49:40 +0000</pubDate>
      <link>https://dev.to/johnkatua/modern-javascript-for-everyone-mastering-modern-javascript-the-right-way-2gc6</link>
      <guid>https://dev.to/johnkatua/modern-javascript-for-everyone-mastering-modern-javascript-the-right-way-2gc6</guid>
      <description>&lt;p&gt;Javascript is one of the popular programming languages in the world. It is used develop web apps, mobile apps, and server side programming. If you are aspiring to become a web developer you should probably take time and understand all the key concept of the modern Javascript. This will make you are better programmer and be able to develop complex project which will land you a better job and also develop project which will have a great and positive impact to the community.&lt;/p&gt;

&lt;p&gt;As a Javascript developer you can choose a path which you want to focus on. There a 3 paths which include Frontend development, Backend Development and Fullstack Development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Development.
&lt;/h2&gt;

&lt;p&gt;In this field you will majorly focus on the user interface. The technologies required in this path include &lt;strong&gt;HTML&lt;/strong&gt;, &lt;strong&gt;CSS&lt;/strong&gt; and of cause &lt;strong&gt;Javascript&lt;/strong&gt;. Some of the popular frontend frameworks include &lt;strong&gt;React&lt;/strong&gt;, &lt;strong&gt;Angular&lt;/strong&gt; and &lt;strong&gt;Vue&lt;/strong&gt; but you do not need to learn all of them so as to be regarded as a Frontend Developer. Some CSS frameworks which you may find useful include &lt;strong&gt;Bootstrap&lt;/strong&gt;, &lt;strong&gt;Material UI&lt;/strong&gt;,&lt;br&gt;
&lt;strong&gt;Tailwind CSS&lt;/strong&gt; and &lt;strong&gt;Bulma&lt;/strong&gt;. &lt;br&gt;
One of the best site you can learn more about Frontend Development is &lt;strong&gt;Frontend Masters&lt;/strong&gt;(&lt;a href="https://frontendmasters.com/"&gt;https://frontendmasters.com/&lt;/a&gt;) and if you are a student you can access courses for free for 6 months on Frontend Masters.&lt;br&gt;
You can use this link to register &lt;br&gt;
(&lt;a href="https://frontendmasters.com/welcome/github-student-developers/"&gt;https://frontendmasters.com/welcome/github-student-developers/&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend Development.
&lt;/h2&gt;

&lt;p&gt;Here you will spend most for you time building &lt;strong&gt;Application Programming Interface&lt;/strong&gt;(APIs). You are required to be familiar with &lt;strong&gt;NodeJS&lt;/strong&gt; in order to be successful in this area. Some of the common frameworks used along with NodeJS include, &lt;strong&gt;ExpressJS&lt;/strong&gt;, &lt;strong&gt;KoaJS&lt;/strong&gt;, &lt;strong&gt;SocketIO&lt;/strong&gt; and &lt;strong&gt;NestJS&lt;/strong&gt;. You should be familiar with at least one those frameworks since it will simplify you work while creating APIs. If you want to be well versed with NodeJS you can go through its documentation (&lt;a href="https://nodejs.org/en/"&gt;https://nodejs.org/en/&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Fullstack Development.
&lt;/h2&gt;

&lt;p&gt;This combines both Frontend and Backend Development but you also need to have some knowledge about databases and some cloud computing. This is for the experienced developers who have been in the industry. Some of the stacks you need to be familiar include &lt;strong&gt;MERN stack&lt;/strong&gt;  (MongoDB, ExpressJS, ReactJS and NodeJS), &lt;strong&gt;PERN stack&lt;/strong&gt; (Postgres, Express, ReactJS, and NodeJS).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you should learn Javascript.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Javascript is easier to learn as compared to other languages, by learning Javascript you will have a better understanding of core programming principles and practices that can be easily transferred to other programming languages.&lt;/li&gt;
&lt;li&gt;Javascript developers are in high demand since most organizations require to have their own websites and this opens more job opportunities for web developers.&lt;/li&gt;
&lt;li&gt;Huge online support is a great advantage for Javascript developers. You can always visit &lt;strong&gt;stack overflow&lt;/strong&gt; in case you get stuck and you are rest assured someone solved the problem for you.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Usage of Javascript.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Adding functionality and increasing user interaction to web pages.&lt;/li&gt;
&lt;li&gt;Developing web  and mobile apps with the help of various Javascript framework e.g React for web developers and React Native for mobile developers.'&lt;/li&gt;
&lt;li&gt;Building web servers and server-side applications using NodeJS.&lt;/li&gt;
&lt;li&gt;Used as a query builder with the help of different libraries e.g KnexJS.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Some of the core concept you need to understand as a Javascript Developer.
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Block binding.&lt;/li&gt;
&lt;li&gt;Strings and Regular Expressions.&lt;/li&gt;
&lt;li&gt;Functions.&lt;/li&gt;
&lt;li&gt;Objects and its functionality.&lt;/li&gt;
&lt;li&gt;Destructuring.&lt;/li&gt;
&lt;li&gt;Symbols and its properties.&lt;/li&gt;
&lt;li&gt;Sets and maps.&lt;/li&gt;
&lt;li&gt;Iterators and generators.&lt;/li&gt;
&lt;li&gt;Javascript classes.&lt;/li&gt;
&lt;li&gt;Arrays.&lt;/li&gt;
&lt;li&gt;Promises and Async await.&lt;/li&gt;
&lt;li&gt;Proxies and the Reflection API.&lt;/li&gt;
&lt;li&gt;Encapsulating code with modules.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Introduction to Data Structures and Algorithms with Modern Javascript.</title>
      <dc:creator>John Katua</dc:creator>
      <pubDate>Mon, 21 Feb 2022 19:59:31 +0000</pubDate>
      <link>https://dev.to/johnkatua/introduction-to-data-structures-and-algorithms-with-modern-javascript-100a</link>
      <guid>https://dev.to/johnkatua/introduction-to-data-structures-and-algorithms-with-modern-javascript-100a</guid>
      <description>&lt;p&gt;&lt;strong&gt;Objectives&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Take an in depth look at Javascript arrays.&lt;/li&gt;
&lt;li&gt;Go through &lt;em&gt;stack _and _queues&lt;/em&gt; in Javascript.&lt;/li&gt;
&lt;li&gt;Finally get a better understanding on how to work with &lt;em&gt;Linked List&lt;/em&gt; data structure in Javascript.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introduction.
&lt;/h2&gt;

&lt;p&gt;In computer science, an array is a data structure consisting of a collection of elements, each identified by one array index or key.&lt;br&gt;
Array play two roles in Javascript:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tuples: Arrays-as-tuples have a fixed number of elements and those elements can be of different types.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sequences: Arrays-as-sequences have a variable number of elements and those elements of the same type.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Fundamental operations in an array.
&lt;/h2&gt;

&lt;p&gt;Arrays have four fundamental operations which include insertion, deletion, access, and search(iteration).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Insertion&lt;/strong&gt;
Insertion operation implies adding a new element inside an existing array. The &lt;em&gt;.push()&lt;/em&gt; method is used to perform  the operation and a new element is added at the end of the array.
Example
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let array = [‘apple’, ‘mango’];
console.log(array); // prints [‘apple’, ‘mango’]
array.push(‘banana’);
console.log(array); // prints [‘apple’, ‘mango’, ‘banana’];

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

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deletion&lt;/strong&gt;
Deletion operation in an array has 2 operations. If you want to remove an element at the end of an array you use the &lt;em&gt;.pop()&lt;/em&gt; method and returns the removed element from the array.
Example,
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1, 2, 3];
console.log(numbers.pop()); // prints 3
console.log(numbers); // prints [1, 2]

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

&lt;/div&gt;


&lt;p&gt;If you want to remove an element at the beginning of an array you use the &lt;em&gt;.shift()&lt;/em&gt; method and returns the removed element.&lt;br&gt;
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 evenNum = [2, 4, 6];
console.log(evenNum.shift()); // prints 2
console.log(evenNum); // prints [4, 6]

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Access&lt;/strong&gt;
Access operation is the process of reading elements in an array and it uses index to get the value directly from the address in memory. It is done by specifying the index of the target element.
&lt;em&gt;N/B: indexing always starts at 0.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let students = ['John', 'Tim', 'Sam'];
console.log(students[0]); // prints John

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Iteration&lt;/strong&gt;
Iteration is the process of accessing each of the items contained within an array. There are multiple ways to iterate through an array in Javascript which include for loop, for (in) loop, for(of) loop and forEach iteration.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;For Loop&lt;/strong&gt;&lt;br&gt;
It is the most common method of iteration. The structure of the loop is:-&lt;/p&gt;

&lt;p&gt;&lt;em&gt;for(variables; Condition; Modification);&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1, 2, 3, 4, 5];
for(let i = 0; i &amp;lt; arr.length; i++) {
    console.log(arr[i]);
} // prints 1, 2, 3, 4, 5

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For in Loop&lt;/strong&gt;
This method prints the index of each element in an array:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arrayOfNames = ['John', 'Nimo', 'Lane', 'Victor', 'Lovell'];
for(let names in arrayOfNames) {
    console.log(names);
}; // prints 0, 1, 2, 3, 4

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For of Loop&lt;/strong&gt;
This method prints out the elements of the array being looped on:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arrayOfNames = ['John', 'Nimo', 'Lane', 'Victor', 'Lovell'];
for(let names of arrayOfNames) {
    console.log(names);
}; // prints all the names in the array

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;For Each&lt;/strong&gt;
For each is the preferred method of iteration because it cannot skip any elements in an array. It is more expressive and explicit by going through each element.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arrayOfNames = ['John', 'Nimo', 'Lane', 'Victor', 'Lovell'];

arrayOfNames.forEach((name, index) =&amp;gt; {
    console.log(name); // print John, Nimo, Lane, Victor, Lovell
  console.log(index); // prints 0, 1, 2, 3, 4
});

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Javascript Functional Array Methods.
&lt;/h2&gt;

&lt;p&gt;We are going to look at three different types of functional array methods in Javascript. They include &lt;strong&gt;map&lt;/strong&gt;, &lt;strong&gt;filter&lt;/strong&gt; and &lt;strong&gt;reduce&lt;/strong&gt; functions. These methods are great because they do not mutate the original array.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Map&lt;/strong&gt;
The &lt;em&gt;map()&lt;/em&gt; method creates a new array populated with the results of calling a provided function on every element in the calling array.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let num = [4, 9, 16, 25, 64];

num.map((val) =&amp;gt; {
    console.log(Math.sqrt(val)); // prints 2, 4, 5, 8
});

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Filter&lt;/strong&gt;
The &lt;em&gt;filter()&lt;/em&gt; method creates a new array with all elements that pass the test implemented by the provided function.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let num = [4, 9, 16, 25, 64];

let res = num.filter((val) =&amp;gt; {
    return val &amp;gt; 20
});

console.log(res); // prints [25, 64];

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reduce&lt;/strong&gt;
The &lt;em&gt;reduce()&lt;/em&gt; method executes a callback function on each element of an array, in order, and calculates the return value from previous elements. The final result is always a single value.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let num = [4, 9, 16, 25, 64];
let res = num.reduce((prevVal, currentVal, index) =&amp;gt; {
    return prevVal + currentVal
});

console.log(res); // prints 118;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stacks and Queues
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stack&lt;/strong&gt;
This is a data structure which is mainly used to remove the last element in an array. It uses the &lt;strong&gt;Last in, First out&lt;/strong&gt; form(LIFO).
Stack has 2 main operations that occur only at the top of the array. The &lt;em&gt;push&lt;/em&gt; and &lt;em&gt;pop&lt;/em&gt; operations  where the push adds an element to the top stack while pop removes the element at the top of the stack.
&lt;/li&gt;
&lt;/ol&gt;

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

stack.push('John');
stack.push('Ann');
console.log(stack); // prints John and Ann

console.log(stack.pop()); // prints Ann
console.log(stack); // prints John

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Queue&lt;/strong&gt; 
Queue is a data structure which allows removal of the first element in an array. It uses the first in, first out form.
A queue has 2 main operations:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enqueue&lt;/strong&gt;&lt;br&gt;
It is a method used to add an element at the end of an array. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dequeue&lt;/strong&gt;&lt;br&gt;
It is a method used to remove an element at the beginning of an array.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of a queue operation:&lt;br&gt;
&lt;/p&gt;

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

Queue.prototype.enqueue = function(e) {
    this.data.push(e);
};

Queue.prototype.dequeue = function(e) {
    return this.data.shift();
}


let newData = new Queue();
newData.enqueue('John');
newData.enqueue('Happy');
console.log(newData.data);// prints John and Happy
newData.dequeue();
console.log(newData.data);// prints Happy

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Linked List
&lt;/h2&gt;

&lt;p&gt;This is a data structure in which each node  points to another node. Linked list has a dynamic structure and can allocate and deallocate data in memory at runtime. There are two types of linked lists:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Singly linked list&lt;/strong&gt;
In a singly linked list the node(element) contains some data and a  pointer to the next node in the list. It allows traversal elements in one way. It is mainly used for implementations of stack.
The following code below is an implementation of a singly linked list:-
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function SinglyLinkedList() {
    this.head = null;
    this.size = 0;
};

SinglyLinkedList.prototype.insert = function(element) {
    if(this.head === null){
    this.head = new SinglyLinkedList(element);
  } else {
    let temp = this.head;
        this.head = new SinglyLinkedList(element);
        this.head.next = temp;
  }
  this.size++;
};

let data = new SinglyLinkedList();
data.insert("apple"); // linked list now is: apple -&amp;gt; null
data.insert("mango"); // linked list now is: mango -&amp;gt; apple -&amp;gt; null

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Doubly linked list&lt;/strong&gt; 
It is different from singly linked list because the node(element) of a doubly linked list contains some data to the next node as well as the previous node in the linked list. You can traverse both ways in the doubly linked list. It can be used to implement heaps, binary trees and stacks.
The following code below is an implementation of a doubly linked list:-
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function DoublyLinkedList() {
  this.head = null;
  this.tail = null;
  this.size = 0;
};

DoublyLinkedList.prototype.insertInTheHead = function(element) {
    if(this.head === null){
    this.head = new DoublyLinkedList(element);
        this.tail = this.head;
  } else {
        let temp = new DoublyLinkedList(element);
        temp.next = this.head;
        this.head.prev = temp
        this.head = temp;
  }
  this.size++;
};


DoublyLinkedList.prototype.insertInTheTail = function(element) {
    if(this.tail === null){
    this.tail = new DoublyLinkedList(element);
        this.head = this.tail;
  } else {
        let temp = new DoublyLinkedList(element);
        temp.prev = this.tail;
        this.tail.next = temp
        this.tail = temp;
  }
  this.size++;
};

let data = new DoublyLinkedList();
data.insertInTheHead("apple"); // tail is apple, head is also apple
data.insertInTheHead("mango"); // tail is apple, head is mango
data.insertInTheTail("banana"); // tail is banana, head is mango

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Introduction to Modern Javascript</title>
      <dc:creator>John Katua</dc:creator>
      <pubDate>Sat, 12 Feb 2022 19:18:45 +0000</pubDate>
      <link>https://dev.to/johnkatua/introduction-to-modern-javascript-m4o</link>
      <guid>https://dev.to/johnkatua/introduction-to-modern-javascript-m4o</guid>
      <description>&lt;p&gt;&lt;strong&gt;Objectives of the article.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get a better understanding of different scopes in javascript.&lt;/li&gt;
&lt;li&gt;Differentiate between var, let, and const and how to apply them in your code.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introduction.
&lt;/h2&gt;

&lt;p&gt;Javascript is a scripting language and is mostly used to build interactive web applications. It was first created for the Netscape web browser in 1995. The first prototype of Javascript was written by &lt;a href="https://en.wikipedia.org/wiki/Brendan_Eich"&gt;Brendan Eich&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with ECMAScript.
&lt;/h2&gt;

&lt;p&gt;ECMAScript was created to standardize Javascript in an attempt to allow for the independent and compatible implementation of various Javascript concepts. The 6th edition, ECMAScript 6(ES6) came with a lot of syntaxes which helped Javascript developers write more complex applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dive into scope.
&lt;/h2&gt;

&lt;p&gt;The scope is a region in a program where the binding of a name to an entity, such as a variable or function is valid. There are two kinds of scopes in Javascript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Function scope&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Block scope&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Function scope.
&lt;/h2&gt;

&lt;p&gt;Function scope is created inside a function. When a function is declared a new scope is created inside that function. Variables declared inside that function cannot be accessed from outside that function but variables outside the function scope can be accessed within the function. Example of a function scope:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "John";
function displayGreetings(){
  let greetings = `Hello ${name}`;
  console.log(name); // prints John
  console.log(greetings); //prints Hello John
};
console.log(greetings); // uncaught ReferenceError: greetings is not defined
displayGreetings();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hoisting
&lt;/h2&gt;

&lt;p&gt;It means that all declarations are moved at the top of the scope before code execution. Functions and variables are always hoisted once they are declared using var. Be sure not to use a variable declared using var without assigning it a value, it will return undefined, and it can cause problems, especially if variables are used in the global scope.&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(num); // prints undefined
num = 20 // assign value
console.log(num); // prints 20
var num; // declare variable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Block scope
&lt;/h2&gt;

&lt;p&gt;Block scope is the area within curly brackets. If statements, switch conditions, for loops and while loops will have their own block scope. In ES6, const and let keywords allow developers to declare variables in the block scope.&lt;br&gt;
Block scope variables are not hoisted therefore cannot be accessed until they are declared. This means variables that are created within the block scope are on the &lt;a href="https://www.freecodecamp.org/news/what-is-the-temporal-dead-zone/"&gt;Temporal Dead Zone&lt;/a&gt; which is the period when a scope is entered and a variable is declared.&lt;/p&gt;
&lt;h2&gt;
  
  
  Variables declaration
&lt;/h2&gt;

&lt;p&gt;In Javascript, you can declare variable using either var, let or const keywords. The let keyword supports the variable reassignment, you can easily reassign your variables. It is also used in block scope and variables  declared using let keyword are not hoisted  e.g&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let student = "John Katua";
console.log(student); // prints John Katua
student = {
  name: "John Katua",
  age:  19
};
console.log(student); // prints the student object
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When using var keyword, you can reassign those variables and you get access to those variables from anywhere in the function.&lt;br&gt;
The const keyword implies that the variable cannot be reassigned(a read-only reference to a value). You cannot also declare a variable without assigning a value e.g:- &lt;br&gt;
&lt;code&gt;const name; // Uncaught SyntaxError: Missing initializer in const declaration&lt;/code&gt;&lt;/p&gt;

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