Part 06 · Practice · 6.3

8 lab JavaScript runtime và TypeScript

Mỗi lab ghi expected semantics trước khi chạy, sau đó dùng test, profiler hoặc browser evidence để giải thích—not chỉ chụp output.

Definition of done: fixture tái chạy được, có happy/failure path, evidence đã ghi version/config và cleanup không để lại listener, process hay secret.
Lab 01 · Values

Coercion và equality matrix

Tạo matrix primitive/object conversions, ===/Object.is/SameValueZero, NaN/zeros/safe integers/decimal. Viết boundary parser explicit và property-based invariants.

Lab 02 · Scope

Closure và module lifecycle

Tái hiện var-loop closure, TDZ, circular ESM và singleton state leak giữa tests/users. Sửa bằng per-iteration binding, dependency/lifecycle rõ; profile retained closure.

Lab 03 · Objects

Prototype/object security

Implement descriptors/prototype/class/private fields; viết unsafe deep merge để tái hiện prototype pollution rồi chặn dangerous keys/validate records. Test cross-realm instanceof caveat.

Lab 04 · Async

Scheduler và cancellation

Vẽ/run task-microtask order, tạo microtask starvation, typed debounce/throttle có cancel/flush, concurrency limiter, stale request race và timeout. Sửa bằng yield, AbortSignal, request version; test fake + real timers phù hợp.

Lab 05 · Browser

Browser API/security

Vanilla app với event delegation, fetch streaming/error/abort, storage choice. Tái hiện unsafe innerHTML/XSS trong sandbox rồi sửa textContent/sanitization/CSP; test CORS vs authz.

Lab 06 · Types

TypeScript state and boundary

Bật strict, noUncheckedIndexedAccessexactOptionalPropertyTypes; model async state bằng discriminated union/exhaustive never. Parse unknown JSON bằng runtime schema; loại any/non-null assertions.

Lab 07 · Library

Generic library và package contract

Viết typed event bus/API client giữ relation key→payload/result; declaration/type tests, ESM exports và consumer project. Tái hiện paths/runtime mismatch và version breaking change.

Lab 08 · Delivery

Performance, tests và supply chain

Bundle app, đo chunks/duplicates/Core Web Vitals/long task/memory; optimize bằng code split/lifecycle cleanup. Thêm unit/DOM/E2E/a11y, lockfile/SCA/secret scan/SBOM và untrusted-PR review.

Rubric

MứcTiêu chí
1Giải thích được output và types.
2Có runtime/browser/type failure tests.
3 · SeniorSecurity/performance/toolchain evidence và production-safe boundary design.