cchakri.aiLearn All courses
// COURSE · PROGRAMMING LANGUAGES

JavaScript

Learn JavaScript from values and functions through objects, asynchronous programming, browser APIs, and testing.

01

Values and language basics

Syllabus

  1. 01Values, types, and equality
  2. 02Variables, scope, and control flow
  3. 03Arrays, objects, and destructuring

Detailed content

Values, types, and equality

JavaScript values include primitives such as string, number, bigint, boolean, null, undefined, and symbol, plus objects. typeof has edge cases, and strict equality avoids most coercion surprises. Use explicit conversion at boundaries and distinguish a missing property from a property whose value is undefined.

Variables, scope, and control flow

const prevents rebinding, while let allows it; var has older function-scoped behavior and is usually avoided in modern code. Blocks create lexical scope. Conditionals and loops control execution. Prefer narrow scopes and clear early returns so the state a function can change remains easy to understand.

Arrays, objects, and destructuring

Arrays represent ordered collections; objects map property keys to values. Destructuring extracts fields into local bindings. Spread syntax copies enumerable properties or array elements, but it is shallow: nested objects remain shared. Use immutable update patterns carefully and avoid assuming a copy isolates nested state.

02

Functions and object behavior

Syllabus

  1. 01Functions, closures, and callbacks
  2. 02Prototypes and classes
  3. 03Modules and package boundaries

Detailed content

Functions, closures, and callbacks

Functions are values that can be passed, returned, and stored. A closure retains access to variables from its lexical scope, which supports callbacks and private state. Arrow functions capture this from their surrounding context; ordinary functions receive this based on how they are called.

Prototypes and classes

Objects can delegate property lookup through a prototype chain. The class syntax provides a clearer form for constructors and methods but still uses prototypes underneath. Prefer composition for shared behavior when inheritance creates fragile coupling. Understand own properties versus inherited properties when debugging object behavior.

Modules and package boundaries

ES modules use import and export to define explicit dependencies. Modules are evaluated once and share their exported bindings. Keep module responsibilities focused and avoid circular imports that create order-dependent initialization. Package scripts and lockfiles make common tasks and dependency versions reproducible.

03

Asynchronous JavaScript

Syllabus

  1. 01The event loop and task queues
  2. 02Promises and async/await
  3. 03Fetch, errors, and cancellation

Detailed content

The event loop and task queues

JavaScript execution runs a call stack while the host environment schedules timers, network events, and other callbacks. Promise reactions run as microtasks before the next task. Long synchronous work blocks rendering and event handling. Break up expensive work or move CPU-heavy processing to a worker.

Promises and async/await

A Promise represents work that may complete later with a value or rejection. then chains transformations; catch handles rejection. async functions return promises, and await pauses that function without blocking the whole runtime. Use try/catch around awaited work and make sure rejected promises are not silently ignored.

Fetch, errors, and cancellation

fetch resolves for HTTP error statuses, so check response.ok before reading the expected data. Parse response bodies according to their format and validate untrusted fields. AbortController cancels requests that are no longer needed. Handle network, status, parsing, and application errors separately so the UI can recover appropriately.

04

Browser APIs and reliable code

Syllabus

  1. 01DOM, events, and forms
  2. 02Storage, timers, and web workers
  3. 03Testing, debugging, and performance

Detailed content

DOM, events, and forms

The DOM represents the current document as nodes. Event listeners respond to interactions; event bubbling can support delegation from a common ancestor. Use semantic forms and controls instead of recreating browser behavior. Validate input, preserve labels and focus, and avoid inserting untrusted strings as HTML.

Storage, timers, and web workers

localStorage persists string values for an origin; sessionStorage is scoped to a tab session. Neither should store secrets. Timers schedule future callbacks but do not guarantee exact timing. Web workers run scripts away from the main thread and exchange messages, making them useful for CPU-heavy work.

Testing, debugging, and performance

Use strict assertions to verify behavior at boundaries, and mock only dependencies that are outside the unit under test. Browser developer tools expose breakpoints, network requests, and performance traces. Measure before optimizing; reduce unnecessary work, memory retention, and blocking scripts that delay interaction.