Add application logic and browser interactions using values, functions and events.
Before starting: HTML, CSS, and browser developer tools.
Practice project: Build a study timer with explicit start, pause, and reset behavior.
1. JavaScript Basics, Syntax & Runtime
- JS Introduction & Browser Engine Architecture
- Where to Insert JS: Internal Script, External File & defer/async
- JS Syntax, Statements, Semicolons & Case Sensitivity
- JS Comments & Developer Documentation
- JS Variables: let, const & var (Scope & Hoisting)
- JS Data Types: Primitives & Reference Types
- JS Typeof Operator & Type Coercion
2. Operators & Control Flow
- Arithmetic & Assignment Operators
- Comparison & Strict Equality (== vs ===)
- Logical Operators (&&, ||, !) & Short-Circuit Evaluation
- If, Else If & Else Conditional Branching
- Ternary Operator (condition ? expr1 : expr2)
- Switch Statement & Strict Case Matching
- Nullish Coalescing (??) & Optional Chaining (?.)
3. Loops & Iteration
- The Classic for Loop & Loop Counters
- While & Do...While Loops
- Break, Continue & Infinite Loop Prevention
- For...of Loop (Iterating Arrays, Strings, Sets)
- For...in Loop (Iterating Object Keys & Properties)
4. Functions & Scope
- Function Declarations, Parameters & Return Values
- Function Expressions & First-Class Functions
- Arrow Functions (() => {}) & Lexical this
- Default Parameters & Rest Parameters (...args)
- Global, Function & Block Scope (and Hoisting)
- Closures & Data Privacy in JavaScript
- Immediately Invoked Function Expressions (IIFE)
5. Arrays & Array Methods
- JavaScript Arrays & Indexing
- Array Stack & Queue Methods (push, pop, shift, unshift)
- Array Slicing vs Splicing (slice vs splice)
- Array Iteration with forEach
- Transforming Arrays with Array.prototype.map()
- Filtering Arrays with Array.prototype.filter()
- Accumulating Values with Array.prototype.reduce()
- Searching Arrays (find, findIndex, includes, some, every)
- Sorting & Reversing Arrays (sort, toSorted, reverse)
6. Objects, Classes & Modern ES6+
- JavaScript Objects & Key-Value Pairs
- The 'this' Keyword & Execution Context
- Destructuring Assignment (Arrays & Objects)
- Spread & Rest Operators (...)
- Template Literals & String Interpolation
- ES6 Classes & Object-Oriented Programming
- Class Inheritance, Extends & super()
- ES Modules (import/export) & JSON Serialization
7. DOM Manipulation & Event Handling
- Selecting DOM Elements (querySelector, getElementById)
- Modifying DOM Content (innerText, textContent, innerHTML)
- Modifying CSS Styles & classList
- Creating & Removing Elements (createElement, appendChild)
- Event Listeners & Handling User Actions
- Event Bubbling, Capturing & Event Delegation
- Form Events, preventDefault() & Real-time Validation
8. Asynchronous JavaScript, APIs & Storage
- Asynchronous JavaScript & The Event Loop
- JavaScript Promises (resolve, reject, .then, .catch)
- async / await Syntax & Elegant Error Handling
- The Fetch API & Consuming REST APIs
- Browser Storage (localStorage, sessionStorage & Cookies)
Modern JavaScript practice
- Search for literal text with RegExp.escape
A course catalog contains CS.101 and CSX101. A student types CS.101 into a search box. Inside a regular expression, a dot can match either a dot or the letter X. Escape the search term before inserting it into a pattern. The anchors below require the entire course code to match. For ordinary exact equality, a string comparison is sufficient. Use this technique when a larger pattern needs to contain literal user text.
A recent browser console or Node.js runtime supporting the named API.
const query = 'CS.101'; const codes = ['CS.101', 'CSX101', 'CS.101B']; const pattern = new RegExp('^' + RegExp.escape(query) + '$'); console.log(codes.filter(code => pattern.test(code)).join(', '));Check the output
CS.101Change the query to C++ and add C++ to the catalog. Predict which entries match.
- Handle a thrown error with Promise.try
A settings loader may return a value, return a promise, or throw before returning. Promise.try calls the loader immediately and gives the caller one promise to await. A thrown exception becomes a rejection. In this example a damaged settings file contains invalid JSON. Follow the order to see when the callback runs and when the error handler runs.
A recent browser console or Node.js runtime supporting the named API.
const events = []; const settings = Promise.try(() => { events.push('read'); return JSON.parse('{'); }); events.push('waiting'); settings.catch(() => { events.push('invalid settings'); console.log(events.join(' -> ')); });Check the output
read -> waiting -> invalid settingsReplace the broken JSON with {}. Add a then handler that records ready and explain why catch no longer runs.
Trace changing state and check loop boundaries
A trace table records the state after each statement. It helps distinguish an incorrect algorithm from a syntax mistake. Write the input contract first: this example accepts a list of numbers and returns their sum. The initial total is zero, so an empty list returns zero.
Paper trace first; pseudocode is not executable. Use your chosen language compiler or interpreter for the implementation.
PSEUDOCODE — translate before running
total ← 0
FOR EACH value IN values
total ← total + value
RETURN totalCheck the output
[2, -1, 4] → 5
[] → 0
[7] → 7
The loop must process each element exactly once.Trace [-3, 3] without running code. Then implement and test it. Explain why starting at the second element loses data. Reject non-number input or explicitly document that it is outside the input contract.
Test JavaScript without a test framework
Start by testing one small function outside the user interface. Node has a built-in test runner and assertion module. The input array below stays unchanged: reduce computes a total without assigning to its elements. A passing test checks observable behavior rather than how many loops the implementation uses.
Node.js 20+; save as an ES module (.mjs)
import test from "node:test";
import assert from "node:assert/strict";
function total(values) {
return values.reduce((sum, value) => sum + value, 0);
}
test("adds values without changing the input", () => {
const values = [4, 6];
assert.equal(total(values), 10);
assert.deepEqual(values, [4, 6]);
});
test("an empty total is zero", () => {
assert.equal(total([]), 0);
});Check the output
Two passing tests. The reporter format and timing depend on your Node version.Add a negative-number case. Decide whether strings are valid input and document your decision before changing the function.
Build and check keyboard-accessible controls
A visible control also needs a name and a predictable keyboard action. A label linked by for and id gives the input an accessible name. A native button supports keyboard activation. CSS can improve appearance, but must preserve visible focus. Client validation helps users; the server must still validate submitted data.
Any modern browser; no framework dependency
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Study reminder</title>
<style>
:focus-visible { outline: 3px solid #075985; outline-offset: 3px; }
</style>
<form action="" method="get">
<label for="topic">Topic to revise</label>
<input id="topic" name="topic" required>
<button type="submit">Save reminder</button>
</form>
</html>Check the output
The page displays a labeled field and a button. Submitting a nonempty value adds topic to the URL; this example has no server-side storage.Add help text using aria-describedby. Test keyboard use at 200% zoom and confirm that the text remains readable.
Validate unknown data before using TypeScript types
TypeScript checks your program before execution; it does not turn a type assertion into an input check. Treat JSON, browser storage, and network responses as untrusted values. The guard below checks the fields used by the application. It deliberately rejects nonfinite numbers and missing names.
TypeScript compiler and Node.js; no third-party runtime libraries
type Score = { name: string; score: number };
function isScore(value: unknown): value is Score {
if (typeof value !== "object" || value === null) return false;
const record = value as Record<string, unknown>;
return typeof record.name === "string"
&& typeof record.score === "number"
&& Number.isFinite(record.score);
}
const input: unknown = JSON.parse('{"name":"Asha","score":75}');
console.log(isScore(input) ? input.score + 5 : "Invalid score");Check the output
80Reject empty names and scores outside 0–100. Keep those business rules separate from the structural type check.
Open the JavaScript learning path on DevStudyHub · Play coding games on this blog
No comments:
Post a Comment
Please do not enter any spam link in the comment box.