Script Valley
JavaScript: The Complete Language
Advanced JavaScript Patterns/Assessment

Practice & Assessment

Test your understanding of Advanced JavaScript Patterns

Multiple Choice Questions

6
1

What is the difference between a named export and a default export in ES modules?

2

Why should you always use Reflect methods inside Proxy handler traps instead of accessing the target directly?

3

Why can't you iterate over a WeakMap?

4

What does a generator function return when called?

5

What happens if you forget to rethrow an error inside a catch block when you can't handle it?

6

What is dynamic import() primarily used for?

Coding Challenges

1
1

Observable State with Proxy

Build a function createObservable(initialState) that uses Proxy to return a reactive object. When any property is set, call all registered listener functions with (key, newValue, oldValue). Implement observable.subscribe(fn) to register a listener and observable.unsubscribe(fn) to remove it. The listeners must be stored privately using a WeakMap. Input: a plain initial state object. Output: the proxy with subscribe and unsubscribe methods. Time estimate: 30 minutes.

Hard

Mini Project

1

Module-Based Task Manager CLI

Build a Node.js task manager split across ES modules. Create tasks.js exporting a TaskStore class backed by a WeakMap for private state, with methods add(text), complete(id), delete(id), getAll(), and getByStatus(status). Create validators.js exporting a Proxy-wrapped validation factory that ensures task text is a non-empty string. Create formatter.js with named exports for formatTask and formatSummary. Create an errors.js with custom TaskNotFoundError and ValidationError classes extending Error. Wire everything in main.js with a CLI that reads commands from process.stdin (add, complete, delete, list, summary). Handle all errors with try-catch and print meaningful messages. Use dynamic import for the formatter to simulate lazy loading.

Hard