In this repo, I'll be mainly sharing my JavaScript learning progress from a frontend development course by freeCodeCamp on YouTube.
Today, I learned about data types and variables in JavaScript.
- String β
"Hello, world!" - Number β
42 - Boolean β
true,false - Object β
{ name: "Waseth", age: 20 }
varβ function-scoped, older way of declaring variables.var name = "Alice"; name = "Bob"; // reassigns, works fine
-
letβ block-scoped, can be reassigned but not re-declared in the same scope.let age = 21; age = 22; // works // let age = 23; error
-
constβ block-scoped, cannot be reassigned.const country = "Kenya"; // country = "Uganda"; error
- I have also complete these five challenges: https://github.com/zachgoll/fullstack-roadmap-series/tree/main/code-challenges.
- You can check out my solutions on the various JS files I have created on this repo under the Variables and data types folder.
Today, I focused on operators in JavaScript, specifically:
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
Used to perform basic math operations:
let x = 10;
let y = 3;
console.log(x + y); // 13
console.log(x - y); // 7
console.log(x * y); // 30
console.log(x / y); // 3.3333
console.log(x % y); // 1
console.log(x ** y); // 1000Assignment operators are used to assign values to variables, often combining assignment with other operations:
| Operator | Explanation | Example | Result |
|---|---|---|---|
= |
Assigns a value to a variable | let a = 5; |
a is 5 |
+= |
Adds a value to the variable and assigns the result | a += 3; |
a = a + 3 β 8 |
-= |
Subtracts a value from the variable and assigns the result | a -= 2; |
a = a - 2 β 6 |
*= |
Multiplies the variable by a value and assigns the result | a *= 2; |
a = a * 2 β 12 |
/= |
Divides the variable by a value and assigns the result | a /= 4; |
a = a / 4 β 3 |
%= |
Takes the remainder of division and assigns it | a %= 2; |
a = a % 2 β 1 |
**= |
Raises the variable to the power of a value and assigns the result | a **= 3; |
a = a ** 3 β 1 |
Example in practice:
let a = 5;
a += 3; // a = 8
a -= 2; // a = 6
a *= 2; // a = 12
a /= 4; // a = 3
a %= 2; // a = 1
a **= 3; // a = 1Used to compare values, returning true or false:
console.log(5 == '5'); // true (loose equality)
console.log(5 === '5'); // false (strict equality)
console.log(10 != 5); // true
console.log(10 !== '10'); // true
console.log(7 > 3); // true
console.log(3 < 7); // true
console.log(5 >= 5); // true
console.log(4 <= 2); // falseUsed to combine or invert conditions:
let isSunny = true;
let isWarm = false;
console.log(isSunny && isWarm); // false (AND)
console.log(isSunny || isWarm); // true (OR)
console.log(!isSunny); // false (NOT)- There are five challenges I have completed.You can find them under the Operators folder
Today, I learned conditionals, loops, and functions in JavaScript.
- If-else (basic syntax and formatting)
- Else if chains for multiple conditions
- Switch statements for cleaner multi-condition logic
Example:
let score = 85;
if (score >= 90) {
console.log("A");
} else if (score >= 75) {
console.log("B");
} else {
console.log("C");
}
// Switch example
let fruit = "apple";
switch(fruit) {
case "apple":
console.log("Red fruit");
break;
case "banana":
console.log("Yellow fruit");
break;
default:
console.log("Unknown fruit");
}- Learned for loops (structure and formatting)
for (let i = 0; i < 5; i++) {
console.log("Number:", i);
}- Function format & syntax
- How to call functions
- Immediately Invoked Functions (IIFE)
- Parameters & arguments
- Scopes (global vs local)
- Anonymous functions stored in variables
- Arrow functions
- Return values (I initially confused this with
console.logbut I later came to understand the difference) - Built-in JS functions (found in documentation)
Examples:
// Regular function
function greet(name) {
return "Hello, " + name;
}
console.log(greet("Waseth"));
// Immediately invoked function
(function() {
console.log("This runs immediately!");
})();
// Arrow function
const add = (a, b) => a + b;
console.log(add(5, 3)); // 8- Here is a link to a collection of all the 25 challenges:https://www.codewars.com/collections/lesson-5-practice-challenges-number-fullstackroadmap
- Check out my solutions in the CodeWars 25 challenges folder
- I am through with the 25 challenges. I have to admit some of them were challenging but I realised looking up things from Google, Stack Overflow or Chatgpt isn't actually cheating. It is through looking them up that I understood most of the concepts especially the built-in Javascript methods.
- Stay tuned for day 6 as I will be learning more about "BUILT-IN JAVASCRIPT UTILITY METHODS"
- I went through how to read Documentations specifically Mozilla Developer Network.
- In this lesson the tutor really emphasized on understanding how callbacks work so I asked chatgpt and it gave me real life examples on how they work and I asked it to give me assignments which I did and they solidified my understanding on callbacks.You can check out my solutions inside the CallBackFunctions folder
- Callbacks are functions passed into other functions to be executed later. Theyβre super important because many built-in JavaScript utility methods depend on them.
Why do we need callbacks?
- For reusability (same logic, different outcomes).
- For asynchronous programming (wait for something to finish before running the next thing).
- Primitive data type β the most basic building blocks in JS (string, number, boolean, null, undefined, symbol, bigint).
- Learned how the
newoperator works (e.g.new Date()creates a date object).
- Basics of writing dates in JS (
new Date()etc.). - Practiced built-in methods:
.getFullYear().getMonth().getDate().getDay().getHours()
- What they mean: a way to match text patterns.
- Learned about Identifiers and Quantifiers.
- Important note: I donβt need to memorize them, but I should know they exist and when to use them.
- Explored useful built-in methods:
.replaceAll().toUpperCase().substring().trim().match()
Got you π β your snippet broke because the code blocks werenβt closed properly and the section headers were inside code fences. Hereβs a clean, valid Markdown README with all array methods formatted properly:
Arrays are one of the most important data structures in JS. I practiced the most common and useful methods that Iβll need almost every day.
push()β adds item(s) at the end.pop()β removes item from the end.
let arr = [1, 2, 3];
arr.push(4); // [1,2,3,4]
arr.pop(); // [1,2,3]shift()β removes first item.unshift()β adds item(s) at the start.
let arr = [2, 3, 4];
arr.unshift(1); // [1,2,3,4]
arr.shift(); // [2,3,4]- Returns a shallow copy of part of the array (non-destructive).
let arr = [10, 20, 30, 40];
console.log(arr.slice(1,3)); // [20,30] (end index not included)
console.log(arr); // [10,20,30,40] (unchanged)- Adds or removes elements in place (destructive).
let arr = [1,2,3,4];
// remove 2 elements starting at index 1
arr.splice(1,2);
console.log(arr); // [1,4]
// insert at index 1
arr.splice(1,0,2,3);
console.log(arr); // [1,2,3,4]indexOf(value)β find index of value.findIndex(callback)β find index based on condition.
let arr = [5, 10, 15];
console.log(arr.indexOf(10)); // 1
console.log(arr.findIndex(n => n > 10)); // 2- Transforms each element β returns new array.
let nums = [1,2,3];
let doubled = nums.map(n => n*2);
console.log(doubled); // [2,4,6]- Runs a function on each element, no return value.
let nums = [1,2,3];
nums.forEach(n => console.log(n*2));
// logs: 2, 4, 6- Checks if array has an element β returns
true/false.
let arr = ["apple","banana","orange"];
console.log(arr.includes("banana")); // true
console.log(arr.includes("grape")); // false- Returns new array with elements that pass a condition.
let nums = [1,2,3,4,5];
let evens = nums.filter(n => n % 2 === 0);
console.log(evens); // [2,4]- Reduces array to a single value (sum, product, etc).
let nums = [1,2,3,4];
let sum = nums.reduce((acc, val) => acc + val, 0);
console.log(sum); // 10JavaScript has a built-in Math object with tons of useful functions.
Itβs not a constructor β you donβt do new Math(). You just call its methods.
console.log(Math.PI); // 3.141592653589793
console.log(Math.sqrt(16)); // 4
console.log(Math.pow(2,3)); // 8
console.log(Math.floor(4.7)); // 4
console.log(Math.ceil(4.2)); // 5
console.log(Math.random()); // random number between 0 and 1Use cases: rounding numbers, generating randoms, math-heavy logic in games/animations.
Errors are part of coding. JavaScript gives you several built-in error types:
ReferenceErrorβ using a variable thatβs not defined.TypeErrorβ wrong type of operation (like calling something thatβs not a function).SyntaxErrorβ typo or invalid code.RangeErrorβ number outside expected range.
// ReferenceError
console.log(x); // x is not defined
// TypeError
let num = 5;
num(); // not a functionundefinedβ default value for variables that havenβt been assigned.nullβ intentional empty value.NaNβ βNot-a-Numberβ, happens when math goes wrong.
let a;
console.log(a); // undefined
let b = null;
console.log(b); // null
let c = "abc" * 3;
console.log(c); // NaNNote:
undefined= JS doesnβt know the value yet.null= dev explicitly said βthis is emptyβ.NaN= invalid math.
Error handling in JavaScript.
try lets you test a block of code.
catch lets you handle errors gracefully.
try {
let result = JSON.parse("{ bad json }");
console.log(result);
} catch (error) {
console.log("Something went wrong:", error.message);
}- Prevents your program from completely crashing.
- Useful in async code (APIs, file reading, etc.).
Lodash is a utility library that makes working with arrays, objects, and functions easier. It gives shortcuts for things youβd normally write a lot of code for.
// Example: _.chunk splits array into groups
let _ = require("lodash");
console.log(_.chunk([1,2,3,4,5], 2));
// [[1,2], [3,4], [5]]
// Example: _.debounce (rate-limit a function)
const log = _.debounce(() => console.log("typing..."), 500);
log(); log(); log(); // only logs once after 500msI noted that: You donβt need Lodash (modern JS has many built-ins), but it can make your life way easier for complex utilities.
- Today I'll be solving these 10 code challenges on Codewars
- My solutions will be on the 10CodeChallenges folder.
September 3rd β 4th, 2025
I built a mini project where:
- A button click triggers a paragraph to pop up.
- Each paragraph shows up with a random number beside it.
- Code lives inside the P-pop-up folder.
This exercise helped me practice basic DOM manipulation and event handling.
- The DOM is a bridge between HTML and JavaScript.
- It represents the page as a tree of nodes (elements, attributes, text).
- With the DOM, JavaScript can read, modify, create, and remove elements dynamically.
windowis the global object in browsers, so you usually donβt need to prefix it.- Examples of properties & methods:
alert("Hello")β shows a pop-up box.scrollBy(0, 200)β scrolls the page vertically by 200px.localStorage.setItem("key", "value")β saves data in browser storage.location.hrefβ gets or sets the current page URL.
I practiced DOM methods that let me create new content on the fly:
document.createElement("p")β makes a new<p>element.document.createTextNode("Hello")β creates a text node.element.appendChild(child)β attaches one node to another.document.createAttribute("id")β creates a new attribute.element.setAttribute("class", "highlight")β sets attributes quickly.
Example:
const para = document.createElement("p");
const text = document.createTextNode("I was added with JS!");
para.appendChild(text);
document.body.appendChild(para);DOM selectors let me target elements for reading or manipulation:
document.getElementById("idName")β grabs one element by ID.document.getElementsByClassName("className")β returns all with that class.document.querySelector("selector")β grabs the first element that matches CSS selector.document.querySelectorAll("selector")β grabs all matching elements (NodeList).
Example:
const button = document.querySelector("#myBtn");
const allParagraphs = document.querySelectorAll("p");Got it β you want a comprehensive README-style doc that breaks down DOM trees, parent/child relationships, nodes, etc., so you can track your learning like proper dev notes. Hereβs a solid one for you:
The DOM (Document Object Model) represents an HTML page as a tree structure.
- Each element (like
<html>,<body>,<p>) is a node in the tree. - The tree starts from the root (
<html>), then branches down into children.
Example HTML:
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Hello</h1>
<p>Welcome!</p>
</body>
</html>This becomes a DOM Tree:
html
βββ head
β βββ title
β βββ "My Page"
βββ body
βββ h1
β βββ "Hello"
βββ p
βββ "Welcome!"
Every piece of the DOM tree is a node. There are different types of nodes:
- Element nodes β HTML elements like
<p>,<div>,<h1>. - Text nodes β The actual text inside an element (
"Hello World"). - Attribute nodes β Represent attributes like
id="btn-1"orclass="highlight". - Document node β The root of the entire HTML document (
document).
The DOM works like a family tree:
-
Parent β The node that contains another node.
- Example:
<body>is the parent of<h1>.
- Example:
-
Child β The node inside another node.
- Example:
<h1>is a child of<body>.
- Example:
-
Siblings β Nodes with the same parent.
- Example:
<h1>and<p>are siblings under<body>.
- Example:
-
Ancestor β Any node above another in the hierarchy.
- Example:
<html>is an ancestor of<p>.
- Example:
-
Descendant β Any node nested inside another.
- Example:
<p>is a descendant of<html>.
- Example:
JavaScript gives methods to navigate the DOM tree:
-
Children
element.childrenβ All child elements (ignores text).element.firstElementChildβ The first child element.element.lastElementChildβ The last child element.
-
Parent
element.parentElementβ The parent of a given element.
-
Siblings
element.nextElementSiblingβ The next sibling.element.previousElementSiblingβ The previous sibling.
Example:
const body = document.querySelector("body");
console.log(body.children); // HTMLCollection of all children of <body>
console.log(body.firstElementChild); // <h1>Hello</h1>- HTMLCollection β Live collection, updates automatically if DOM changes.
- NodeList β Static collection (doesnβt auto-update unless re-selected).
Example:
document.getElementsByTagName("p"); // HTMLCollection
document.querySelectorAll("p"); // NodeList- In the next lesson I'll be following along and trying to figure out how to complete the given assignment
- Having already learned CSS over the past couple of weeks I won't get into the crash course but I'll just straight into the first challenge from FRONTEND MENTOR
- Check Out Pricing card challenge to see my solution, here's the link
- Today comes the end of this repository's progress log. Moving forward, I'll be building real JS projects with the help of a few youtube tutorials to help me solidify my Javascript skills.