useless_engineer.dev retweeted
const cfg = Object.freeze({ ui: { dark: false } });
cfg.ui = null; // ignored
cfg.ui.dark = true; // works
freeze is shallow: the top level is locked, nested objects still change. In strict mode the blocked write throws a TypeError. Freeze each level for a deep lock.
Object.freeze only locks the top-level properties. A nested object is a separate object nobody froze, so cfg.db.port = 1 still works and the "frozen" config keeps changing underneath you.
#javascript #react #typescript
instagram.com/reel/De3Uvu0qa…
P148: const blocks reassignment of the binding, not mutation of the value it points at. push, splice and property writes still change the same object, and everything holding that reference sees it.
#javascript #react #typescript
instagram.com/reel/De0e7hzqU…
P146: typeof [] is "object". So is typeof {} and typeof null.
#javascript #react #typescript
instagram.com/reel/DevWKgDKT…
A validation check meant to mean "a plain object" lets arrays and null slip straight through, and the bad value breaks something deep inside instead of at the check.
Array.isArray answers the array question directly.
useless_engineer.dev retweeted
const { matches } = matchMedia(
"(prefers-reduced-motion: reduce)"
);
if (!matches) startConfetti();
matchMedia runs a CSS media query from JS. If someone turned on reduced motion in their OS, matches is true, so skip or tone down big animations. Listen for "change" too.
Finding the longest run of consecutive integers by sorting first works, but it pays an n log n fee just to impose an order the answer never needed.
#DSA
leetcode.com/problems/longes…
#Leetcode
instagram.com/p/DeuFcY6iviW/…
useless_engineer.dev retweeted
const a = ["js", "css"];
const b = a.with(1, "scss");
a // ["js", "css"]
b // ["js", "scss"]
with(index, value) returns a copy with one item swapped and leaves the original untouched, handy for React state. A negative index counts from the end.
P144: delete arr[i] removes the key entirely, leaving a real hole — but .length doesn't shrink, so the array keeps reporting its old count while sparse underneath.
#javascript #react
instagram.com/reel/DetP3UIqr…
A closure captures its entire enclosing scope, not just the variables it reads.
#javascript #react #typescript
instagram.com/reel/DermHSHKr…
A listener that only logs bigData.length still keeps the whole million-item array reachable — un-garbage-collectable — as long as the listener is attached, even after the DOM node is removed.
One Flash Could Kill You in Stalingrad: The Sniper
Exploring #AI
instagram.com/reel/DeqzZAXqS…
P140: An IIFE with no return statement evaluates to undefined, like any function. The "private" variables you wrote still exist, just trapped in a closure nothing outside can reach.
#javascript #react #typescript
instagram.com/reel/Den1IXXKa…

