Memory Card Matching Game - Online Flip & Find Pairs
Classic memory card game with emoji or color themes. Select grid size and try to find all pairs in minimum moves. Brain training fun.
UD5 Toolkit
| Feature | Map | WeakMap | Set | WeakSet |
|---|---|---|---|---|
| Key / Value Type | Any type | Keys: Objects only | Any type | Values: Objects only |
| Iterable | Yes | No | Yes | No |
| .size property | Yes | No | Yes | No |
| .clear() method | Yes | No | Yes | No |
| Key references | Strong | Weak (GC-friendly) | Strong | Weak (GC-friendly) |
| Prevents GC of keys | Yes (risk of leak) | No | Yes (risk of leak) | No |
| Common Use Case | General key-value storage | Object metadata, caches, private data | Unique value collections | Object tagging / "processed" markers |
// WeakMap: Store DOM element metadata without memory leaks
const elementData = new WeakMap();
function attachData(el, data) {
elementData.set(el, data);
}
function getData(el) {
return elementData.get(el);
}
// When the DOM element is removed, its WeakMap entry
// becomes eligible for garbage collection automatically.
// No manual cleanup needed — no memory leak!
The fundamental difference lies in how they hold references to their keys:
Because of weak references, WeakMap keys must be objects (not primitives), and WeakMaps are not iterable — you cannot enumerate their contents because entries may disappear at any time.
WeakMap and WeakSet are non-iterable by design. The reason is tied to garbage collection:
The lack of iteration is not a limitation — it's a feature that ensures weak references remain truly weak and GC-friendly.
For the same reason they're not iterable: the size is non-deterministic. Entries can be garbage collected at any time, so the count would constantly change in ways that JavaScript can't reliably track. Exposing a .size would give a false sense of precision. If you need to know the size or iterate entries, use a regular Map or Set instead.
WeakMap excels in scenarios where you need to associate data with objects without preventing their garbage collection:
WeakSet is ideal for tagging or marking objects:
JavaScript engines use mark-and-sweep garbage collection. Here's how it interacts with weak collections:
Important: GC timing is non-deterministic. You cannot predict exactly when an object will be collected. Use FinalizationRegistry to get callbacks when specific objects are GC'd.
Yes, absolutely. WeakMap and WeakSet are specifically designed to prevent a common class of memory leaks:
This is why frameworks like Vue 3, Svelte, and modern libraries use WeakMap extensively for internal bookkeeping.
FinalizationRegistry provides callbacks when registered objects are garbage collected, but with important caveats:
It's a useful diagnostic tool but not a substitute for proper memory management.
Both WeakMap and WeakSet have excellent browser support:
WeakMap and WeakSet are safe to use in production without polyfills for virtually all modern web applications.
Classic memory card game with emoji or color themes. Select grid size and try to find all pairs in minimum moves. Brain training fun.
Place multiple grid items into the same cells to create overlapping layouts. Learn the technique visually. Copy code.
Simulate memory page reference strings with FIFO, LRU, and Optimal algorithms. See page fault count. OS concept demo.
Control image‑orientation: from-image vs none. See how the browser interprets EXIF rotation. Fix portrait photos.
Experiment with scroll‑state container queries to style elements when they are stuck, snapped, or overflowed. Experimental.
Configure how your PWA launches: focus existing or create new. Test with the launch_handler manifest field.
Build a horizontal scroll‑snap container with configurable snap‑type and alignment. Perfect for image galleries.
Compare all CSS easing presets side by side on a bouncing ball. See which curve fits your UI animation.
Query the permission state of camera, microphone, geolocation, and more. See the response and learn the API.
Process audio faster than real‑time with OfflineAudioContext. Apply filters and export the result. Dev tool.
Drop files onto a zone and see a preview with name, size, and type. Copy the JavaScript pattern for your site.
Demonstrate how to add custom headers and POST‑like functionality to EventSource using a polyfill. Code and example.
Scroll a container and see how sticky elements behave. Adjust top, bottom, and scroll margins. Copy the code.
See how overflow: visible, hidden, scroll, and auto behave with real content. Clone to test with your text.
See the difference between clone and slice on inline boxes that break across lines. Useful for multi‑line headings.
Render the classic Stanford Bunny with a basic WebGPU pipeline. Rotate and zoom. Check if your browser supports WebGPU.
See how scroll‑padding and scroll‑margin affect the position of elements when using anchor links or scroll‑snap. Visual.
Test the experimental Translation API to translate text between languages directly in the browser, without cloud calls. Check support and copy the JavaScript starter.
Apply a convolution filter (blur, sharpen) using a Web Worker. See the UI stay responsive while processing. Learn multithreading in the browser.
Toggle scrollbar‑gutter: stable to reserve space for the scrollbar and avoid content jumps. Visual demo with two columns.
Acquire and release locks across tabs. Prevent race conditions in IndexedDB or localStorage. Visual queue and lock state.
Register a periodic background sync to fetch fresh data even when the tab is closed. Understand the API and limits.
Test the Fullscreen API: request fullscreen on a colored div, detect changes, and copy the JavaScript boilerplate.
See the View Transitions API in action. Cross‑fade and morph between two states. Copy the JavaScript starter code.
A sequence of digits flashes for a few seconds. Type it back. Increase length. Improve your working memory.
See how many tabs you have open and estimate memory usage based on navigator object. Fun productivity check.
Watch and repeat the growing sequence of colored buttons. How long is your memory? Classic electronic game replica.
Find safe mixing ratios for the classic elephant toothpaste demonstration. Volume adjustments for different container sizes.
Watch a color sequence and click the same pattern. Gets longer each round. Test and improve your working memory. All local.
Repeat the growing color sequence. How far can you go? Classic memory game with sound and animations.