๐ Week 5 Day 6: Debugging, Storage, Modules, Promises, and More APIs
Hey hey Campers! ๐๐ป
Weโve come such a long way together. From writing our first console.log("Hello World") to handling APIs and promises .๐ช
Today is our last big frontend JavaScript lesson. After this, youโll be fully ready to step into backend land. But before that, letโs tie up the remaining pieces:
๐ 1. Debugging in JavaScript
Debugging means finding and fixing errors (bugs) in your code.
๐ Think of it like when your bicycle makes a strange sound ๐ฒ๐ โ you stop, check where itโs coming from, and fix the loose screw. Debugging in code is the same!
Common Debugging Tools:
โคconsole.log()
Your best friend ๐ถ. Use it to print values and see whatโs happening.
โคBreakpoints (in Browser DevTools)
Open F12 โ Sources โ Add breakpoints in code. The program stops and lets you inspect step by step.
โคErrors & Stack Traces
When you see red error messages โ in the console, donโt panic. They usually tell you where the problem is.
Example:
๐ Lesson: Errors are not enemies. They are guides telling you what went wrong.
๐พ 2. Local Storage & Session Storage
Your browser can remember things using storage, even if you refresh or close the tab.
โคLocal Storage โ Data stays until you delete it (like saving something in your notebook ๐).
โคSession Storage โ Data disappears when you close the tab (like notes on a whiteboard ๐งฝ).
Example: Local Storage
Example: Session Storage
๐ก Hint: Use Local Storage for things like to-do lists, Session Storage for things like temporary form data.
๐ฆ 3. Modules in JavaScript
Imagine your code is a library ๐. Instead of putting all books in one giant pile, you divide them into sections (math, history, science).
Modules let us split code into files and reuse it.
Example:
๐ project
โฃ ๐ math.js
โ ๐ app.js
math.js
app.js
๐ก Modules keep your code organized and easy to maintain.
โณ 4. Multiple Promises (Promise.all, Promise.race)
So far, weโve seen one promise at a time. But what if we want to wait for many tasks?
๐ Think of it like ordering injera and shiro at the same time. You want to start eating only when both are ready. ๐ฝ๏ธ
Promise.all
Waits for all promises to finish.
Promise.race
Whoever finishes first, wins.
Hey hey Campers! ๐๐ป
Weโve come such a long way together. From writing our first console.log("Hello World") to handling APIs and promises .๐ช
Today is our last big frontend JavaScript lesson. After this, youโll be fully ready to step into backend land. But before that, letโs tie up the remaining pieces:
๐ 1. Debugging in JavaScript
Debugging means finding and fixing errors (bugs) in your code.
๐ Think of it like when your bicycle makes a strange sound ๐ฒ๐ โ you stop, check where itโs coming from, and fix the loose screw. Debugging in code is the same!
Common Debugging Tools:
โคconsole.log()
Your best friend ๐ถ. Use it to print values and see whatโs happening.
let num = 10;
console.log("The number is:", num); โคBreakpoints (in Browser DevTools)
Open F12 โ Sources โ Add breakpoints in code. The program stops and lets you inspect step by step.
โคErrors & Stack Traces
When you see red error messages โ in the console, donโt panic. They usually tell you where the problem is.
Example:
function divide(a, b) {
if (b === 0) { throw new Error("You can't divide by zero!"); }
return a / b; }
try { console.log(divide(10, 0)); }
catch (err) { console.error("Something went wrong:", err.message); } ๐ Lesson: Errors are not enemies. They are guides telling you what went wrong.
๐พ 2. Local Storage & Session Storage
Your browser can remember things using storage, even if you refresh or close the tab.
โคLocal Storage โ Data stays until you delete it (like saving something in your notebook ๐).
โคSession Storage โ Data disappears when you close the tab (like notes on a whiteboard ๐งฝ).
Example: Local Storage
// Save
localStorage.setItem("username", "Megersa");
// Get
let user = localStorage.getItem("username");
console.log("Welcome back,", user);
// Remove localStorage.removeItem("username");Example: Session Storage
sessionStorage.setItem("theme", "dark"); console.log(sessionStorage.getItem("theme")); // "dark" ๐ก Hint: Use Local Storage for things like to-do lists, Session Storage for things like temporary form data.
๐ฆ 3. Modules in JavaScript
Imagine your code is a library ๐. Instead of putting all books in one giant pile, you divide them into sections (math, history, science).
Modules let us split code into files and reuse it.
Example:
๐ project
โฃ ๐ math.js
โ ๐ app.js
math.js
export function add(a, b) { return a + b; }
export const PI = 3.14; app.js
import { add, PI } from './math.js';
console.log(add(5, 10)); // 15
console.log(PI); // 3.14 ๐ก Modules keep your code organized and easy to maintain.
โณ 4. Multiple Promises (Promise.all, Promise.race)
So far, weโve seen one promise at a time. But what if we want to wait for many tasks?
๐ Think of it like ordering injera and shiro at the same time. You want to start eating only when both are ready. ๐ฝ๏ธ
Promise.all
Waits for all promises to finish.
let p1 = Promise.resolve("Injera ready");
let p2 = Promise.resolve("Shiro ready");
Promise.all([p1, p2]).then(values => { console.log(values); // ["Injera ready", "Shiro ready"] }); Promise.race
Whoever finishes first, wins.
let fast = new Promise(res => setTimeout(() => res("Fast delivery"), 1000));
let slow = new Promise(res => setTimeout(() => res("Slow delivery"), 3000));
Promise.race([fast, slow]).then(value => { console.log(value); // "Fast delivery" });๐ 5. More on APIs (GET vs POST)
So far, we mostly fetched data (GET). But sometimes we want to send data (POST).
๐ Think of GET like reading a book from the library, and POST like writing your own book and giving it to the library ๐.
Example: GET (fetch data)
Example: POST (send data)
๐ก Lesson: GET = ask data ๐ง, POST = give data โ๏ธ.
๐ฏ Wrap-Up
Today we learned:
๐ Debugging with console, errors, try/catch
๐พ Local & Session Storage
๐ฆ ES6 Modules (import/export)
โณ Handling Multiple Promises (all, race)
๐ More API calls (GET vs POST)
So far, we mostly fetched data (GET). But sometimes we want to send data (POST).
๐ Think of GET like reading a book from the library, and POST like writing your own book and giving it to the library ๐.
Example: GET (fetch data)
fetch("https://jsonplaceholder.typicode.com/posts/1") .then(res => res.json()) .then(data =>
console.log(data));
Example: POST (send data)
fetch("https://jsonplaceholder.typicode.com/posts",
{ method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ title: "My New Post", body: "Hello campers!", userId: 1 }) })
.then(res => res.json())
.then(data => console.log("Saved:", data)); ๐ก Lesson: GET = ask data ๐ง, POST = give data โ๏ธ.
๐ฏ Wrap-Up
Today we learned:
๐ Debugging with console, errors, try/catch
๐พ Local & Session Storage
๐ฆ ES6 Modules (import/export)
โณ Handling Multiple Promises (all, race)
๐ More API calls (GET vs POST)
Hello campers ๐
Since we are done with js , you will be working with some projects that are meant to combine everything youโve learned so far (HTML/CSS/JS, DOM, events, async/fetch, promises, localStorage, modules).
Are you ready??
Since we are done with js , you will be working with some projects that are meant to combine everything youโve learned so far (HTML/CSS/JS, DOM, events, async/fetch, promises, localStorage, modules).
Are you ready??
Anonymous Poll
70%
๐ let's go
30%
๐ not yet
Forwarded from Edemy
"Nothing humbles a developer more than debugging the wrong environment or file for an hour straight."
It happens to everyone. Hours can be spent testing and refreshing, changing code, and still getting nowhereโฆ until the solution suddenly appears in a completely unexpected place.
Debugging is part of the job, but some habits make it faster, less stressful, and even a little fun.
1. Step away when stuck
The mind often works in the background. Solutions sometimes appear while stretching, going for a short walk, or just taking a few minutes to clear your head. A fresh perspective can reveal what a tired mind misses.
2. Talk it out or write it down
Explaining the problem out loud to a teammate, your self or writing the steps on paper can highlight mistakes and gaps in logic that are easy to miss when thinking silently.
3. Donโt guess, ask the right questions
Instead of randomly changing code, slow down and ask: What caused this? Where did it first go wrong? Which assumption failed? Guided questioning often uncovers the problem faster than trial and error.
4. Check the basics
Many bugs arenโt in the code itself. They come from simple things: a wrong file path, an unset environment variable, or a missing dependency. Always verify the setup before digging deeper.
5. Learn from past bugs
Every bug teaches something. After fixing one, pause and reflect: Why did this take so long? What misled the process? How could it have been caught earlier? Sharing these insights builds a team culture that improves over time.
6. Use logging and debugging tools effectively
Structured logs, breakpoints, and debug tools can save hours of trial and error. Log meaningful information like variable states, timestamps, or request details, so itโs easy to see where things go wrong. This makes debugging more predictable and less frustrating.
Debugging will always humble developers. But with the right habits, it becomes less frustrating, more educational, and sometimes even a chance to laugh at how simple the fix really was.
And yesโฆ sometimes the villain is still just the cache. ๐
@edemy251
It happens to everyone. Hours can be spent testing and refreshing, changing code, and still getting nowhereโฆ until the solution suddenly appears in a completely unexpected place.
Debugging is part of the job, but some habits make it faster, less stressful, and even a little fun.
1. Step away when stuck
The mind often works in the background. Solutions sometimes appear while stretching, going for a short walk, or just taking a few minutes to clear your head. A fresh perspective can reveal what a tired mind misses.
2. Talk it out or write it down
Explaining the problem out loud to a teammate, your self or writing the steps on paper can highlight mistakes and gaps in logic that are easy to miss when thinking silently.
3. Donโt guess, ask the right questions
Instead of randomly changing code, slow down and ask: What caused this? Where did it first go wrong? Which assumption failed? Guided questioning often uncovers the problem faster than trial and error.
4. Check the basics
Many bugs arenโt in the code itself. They come from simple things: a wrong file path, an unset environment variable, or a missing dependency. Always verify the setup before digging deeper.
5. Learn from past bugs
Every bug teaches something. After fixing one, pause and reflect: Why did this take so long? What misled the process? How could it have been caught earlier? Sharing these insights builds a team culture that improves over time.
6. Use logging and debugging tools effectively
Structured logs, breakpoints, and debug tools can save hours of trial and error. Log meaningful information like variable states, timestamps, or request details, so itโs easy to see where things go wrong. This makes debugging more predictable and less frustrating.
Debugging will always humble developers. But with the right habits, it becomes less frustrating, more educational, and sometimes even a chance to laugh at how simple the fix really was.
And yesโฆ sometimes the villain is still just the cache. ๐
@edemy251
Full Stack Camp pinned ยซHello campers ๐
Since we are done with js , you will be working with some projects that are meant to combine everything youโve learned so far (HTML/CSS/JS, DOM, events, async/fetch, promises, localStorage, modules).
Are you ready??ยป
Since we are done with js , you will be working with some projects that are meant to combine everything youโve learned so far (HTML/CSS/JS, DOM, events, async/fetch, promises, localStorage, modules).
Are you ready??ยป
1. Which of the following is NOT a JavaScript data type?
Anonymous Quiz
8%
a) String
42%
b) Number
8%
c) Boolean
42%
d) Character
2. What is the correct way to declare a variable in modern JS?
Anonymous Quiz
0%
a) variable x = 5;
86%
b) let x = 5;
14%
c) dim x = 5;
0%
d) var: x = 5;
3. What does === check in JavaScript?
Anonymous Quiz
13%
a) Only value
75%
b) Value and type
13%
c) Only type
0%
d) None of the above
4. What will typeof null return?
Anonymous Quiz
13%
a) "null"
25%
b) "object"
63%
c) "undefined"
0%
d) "string"
5. Which loop is guaranteed to run at least once?
Anonymous Quiz
63%
a) for loop
13%
b) while loop
25%
c) do...while
0%
d) for...of
6. Which of these is a function expression?
Anonymous Quiz
43%
a) function greet() { }
29%
b) let greet = function() { }
14%
c) greet() => { }
14%
d) def greet() { }
7. What does this refer to inside a regular function (not strict mode)?
Anonymous Quiz
0%
a) Always the global object
50%
b) The function itself
25%
c) Undefined
25%
d) The parent object
โค1
8. Which of these creates a copy of an array?
Anonymous Quiz
0%
a) let b = a;
40%
b) let b = [...a];
40%
c) let b = a; b[0] = 99;
20%
d) None of the above
9. Which array method is a higher-order function?
Anonymous Quiz
17%
a) push()
83%
b) filter()
0%
c) length
0%
d) pop()
10. What will this print?
setTimeout(() => console.log("Hello"), 0);
console.log("World");
setTimeout(() => console.log("Hello"), 0);
console.log("World");
Anonymous Quiz
33%
a) Hello World
50%
b) World Hello
17%
c) Error
0%
d) Hello only
12. What does JSON stand for?
Anonymous Quiz
0%
a) JavaScript Oriented Nodes
40%
b) Java Standard Object Notation
60%
c) JavaScript Object Notation
0%
d) Java Syntax Over Network