Organise big programs with classes and modules, debug like a pro, use browser APIs and build five complete apps.
Every example opens in a live browser preview. Click ✎ Edit on any preview, or press L, to open the Code Lab.
new Chart(...)| Part | Job |
|---|---|
class Student | the blueprint (name starts with a capital) |
constructor() | runs once for every new |
this.name = name | saves data inside the object |
grade() | a method: an action every student has |
| Feature | Use it for |
|---|---|
#field | data nobody outside may change (balance, password hash) |
get x() | read-only or calculated values |
set x(v) | check a value before saving it |
static | belongs to the class, not each object |
#balance can only change through deposit() and withdraw().Teacher extends Person gets name and age for free.shape.area() works for Circle, Square and Triangle.cart.checkout() hides 50 lines of work.Ride is the parent; AutoRide, CabRide, BikeRide each override fare().function Dog(name) {...} and Dog.prototype.bark = .... You will still see this in old code.file://. Open the folder with VS Code Live Server (or any local server).| Named export | Default export | |
|---|---|---|
| Write | export const tax = 0.18; | export default class Cart {} |
| Import | import { tax } from "./x.js" | import Cart from "./cart.js" |
| How many per file | many | one |
| Rename on import | import { tax as GST } | any name you like |
| Typical use | helper functions, constants | the main class or component |
export default function Navbar() {...}, then import Navbar from "./Navbar.js".remove(name) method and a Remove button. Add a get discount() that gives 10% off above Rs. 500. Try cart.#items in the console and read the error.fare(), so the loop does not care which type it is. That is polymorphism.Module 19: Debugging, browser APIs (location, clipboard, canvas, speech) and best practices.
Q1. What runs automatically when you write new Student()?
Q2. What must a child constructor call before using this?
Q3. #balance means the field is:
console.log("Hi" — missing ).user.name when user is null.total = price + qty instead of *.Uncaught TypeError: Cannot read properties of null (reading 'name') at app.js:14 tells you what (TypeError), why (null) and where (line 14).| Method | Use it for |
|---|---|
console.table | arrays of objects, API data |
console.warn / error | yellow / red messages, easy to spot |
console.time | how long code takes |
console.log({ x }) | shows the name AND the value |
debugger; on any line. With DevTools open, the browser pauses there automatically.| Symptom | First thing to check |
|---|---|
| Button does nothing | Console errors; is the listener attached? Is the id correct? |
| undefined on screen | console.log the object; check spelling of the property |
| Data not loading | Network tab: status code and response |
| Works once, then breaks | Is something added twice (listeners, intervals)? |
| Command | Draws |
|---|---|
getContext("2d") | gets the pen |
fillStyle = "red" | chooses the colour |
fillRect(x, y, w, h) | a filled rectangle |
fillText(t, x, y) | text |
beginPath, arc, lineTo, stroke | circles and lines |
clearRect | erase (before each animation frame) |
| API | What it does | Real use |
|---|---|---|
speechSynthesis | text → voice | read-aloud news |
IntersectionObserver | is an element on screen? | lazy images, scroll animations |
navigator.share | phone share sheet | "Share on WhatsApp" |
Notification | system pop-ups | new message alerts |
navigator.onLine | online / offline | "You are offline" banner |
matchMedia | media queries in JS | dark-mode detection |
textContent, not innerHTML (stops XSS attacks)<img src=x onerror=alert(1)> is shown with innerHTML, it runs as code on every visitor's browser.loading="lazy")deferpad.toDataURL() after each stroke. Use it as a signature box on a form.Module 20: put everything together in 5 complete capstone apps.
Q1. Which DevTools tab shows whether a fetch returned 404?
Q2. Showing user comments safely uses:
Q3. Where should a secret API key live?
| Step | Tip |
|---|---|
| Plan | Draw the screens on paper. List the data (what is in the array?) and the functions. |
| State | Keep ALL data in one array or object. |
| Render | One function draws everything from the data. |
| Events | Change the data, then call render(). Never patch the screen by hand. |
| Save | save() after every change, load on start. |
| Test | Empty list, wrong input, slow or failed network, refresh. |
todos = [{id, text, done, high}] and filter/api/quiz with a loading state/api/quiz as {q, options, answer}.entries = [{id, title, amount, type, cat, date}]toLocaleString("en-IN")/api/weather?city=NAME for Ranchi, Dhanbad, Jamshedpur, Bokaro, Deoghar, Hazaribagh and Netarhat. /api/slow and unknown cities test the other states./api/products with a loading state/api/ordersgit push)yourname.github.io/todo-app20 modules · 95 practice examples · 5 capstone apps
BrainBit Infotech, Ranchi
Publish your best two apps and share the links with your trainer!
Q1. After changing the data array, what should you call?
Q2. Which state is often forgotten?
Q3. Where can you host these apps for free?
You have finished Part 4 of the Complete JavaScript Course.
Publish your apps, keep building and share your portfolio. Congratulations from BrainBit Infotech!