Remind Me JavaScript (@remindmejs) header
Remind Me JavaScript (@remindmejs) profile picture

#JavaScript reminders for people who are keep losing the details. Short code, a plain explanation, one thing worth remembering everyday. @remindmepython

Joined March 2025
every() is true on an empty array ✅ [].every(Boolean); // true [].some(Boolean); // false Vacuous truth: with no items, nothing can fail every(), and nothing can pass some(). Guard against empty lists when "all valid" really matters.
3
Promise.any() ignores rejections 🏁 const { any } = Promise; const r = await any([ Promise.reject(1), Promise.resolve("ok"), ]); // r is "ok" First fulfilled wins; AggregateError only if all reject. race() takes the first to settle.
7
Array destructuring skips with commas 🕳️ const [, second, , fourth] = [10, 20, 30, 40]; console.log(second, fourth); // 20 40 Empty slots between commas ignore those positions, so you can grab only the items you need.
12
Optional catch binding 🪤 try { JSON.parse(input); } catch { console.log("bad JSON"); } If you don't need the error object, skip the (err) part. Since ES2019, catch can have no binding at all.
10
split() takes a limit ✂️ "a,b,c,d".split(",", 2); // ["a", "b"] "a,b,c,d".split(",", 0); // [] The limit caps how many pieces you get back. The rest is dropped, not joined into the last piece like in Python or Java.
1
40
Set methods: intersection() 🤝 const a = new Set([1, 2, 3]); const b = new Set([2, 3, 4]); [...a.intersection(b)]; // [2, 3] [...a.difference(b)]; // [1] Newer Sets have union, intersection, difference & more. They return a new Set, no manual filter loops.
15
Swap variables without a temp 🔀 let a = 1, b = 2; [a, b] = [b, a]; // a is 2, b is 1 The right side builds an array first, then destructuring assigns it back. Start the line with a semicolon if the previous line has none.
14
trunc() cuts, floor() rounds down ✂️ const n = -4.7; Math.floor(n); // -5 Math.trunc(n); // -4 floor goes toward -Infinity, trunc just drops the decimals. They only differ for negative numbers.
14
Date months start at 0 📅 const d = new Date(2026, 0, 15); d.getMonth(); // 0 (January) d.getDate(); // 15 (days start at 1) new Date(2026, 12, 1); // Jan 1, 2027 (overflows) Months are 0–11, but days are 1–31. Out-of-range values roll over instead of throwing.
2
32
flatMap() maps, then flattens one level 🪜 const words = ["hi yo", "ok"]; const out = words.flatMap((w) => w.split(" ")); console.log(out); // ["hi", "yo", "ok"] Return [] to drop an item, so it can filter and map in one pass. Only one level is flattened.
22
WeakSet holds objects weakly 🧷 const seen = new WeakSet(); const obj = {}; seen.add(obj); seen.has(obj); // true seen.add(1); // TypeError Only objects go in, you can't loop over it, and an entry disappears once nothing else references the object.
17
toString() accepts a radix 🔢 (255).toString(16); // "ff" (5).toString(2); // "101" parseInt("ff", 16); // 255 Pass a base from 2 to 36 to write a number in that base. parseInt with the same base reads it back.
20
Object getters run on every read 🧮 const box = { w: 2, h: 3, get area() { return this.w * this.h; } }; box.w = 5; const { area } = box; console.log(area); // 15 A getter looks like a property but runs a function on each read, so it's never stale.
1
23
Integer keys come first in objects 🔢 const { keys } = Object; const o = { b: 1, 2: 1, a: 1, 1: 1 }; keys(o); // ["1", "2", "b", "a"] Integer-like keys are listed in ascending order, then string keys in insertion order. Don't rely on insertion order for numeric keys.
27
String.raw keeps backslashes 🧵 const { raw } = String; "a\nb".length; // 3 raw`a\nb`.length; // 4 A normal string turns \n into a newline. A raw template leaves the characters as typed: handy for regex sources and Windows paths.
29
Promise.allSettled() never rejects 🛡️ const out = await Promise.allSettled([ Promise.resolve(1), Promise.reject(new Error("no")), ]); // [{ status: "fulfilled", value: 1 }, // { status: "rejected", reason }] One failure doesn't discard the rest.
26
Array.fromAsync() awaits for you ⏳ async function* gen() { yield 1; yield 2; } const { fromAsync } = Array; const arr = await fromAsync(gen()); console.log(arr); // [1, 2] It collects an async iterable (or promises) into a real array. Array.from can't await anything.
15
Array sort() is lexicographic by default 🔤 const nums = [10, 9, 1, 100]; nums.sort(); console.log(nums); // [1, 10, 100, 9] nums.sort((a, b) => a - b); console.log(nums); // [1, 9, 10, 100] Without a compare function, items are sorted as strings. Pass one for numbers.
14
freeze() is shallow ❄️ const { freeze } = Object; const cfg = freeze({ inner: { n: 1 } }); cfg["inner"]["n"] = 2; console.log(cfg["inner"]["n"]); // 2 freeze only locks the top level. Nested objects stay mutable unless you freeze them too.
16
includes() finds NaN, indexOf() doesn't 🔍 const a = [NaN]; a.includes(NaN); // true a.indexOf(NaN); // -1 includes() compares with SameValueZero, so NaN matches itself. indexOf() uses ===, and NaN === NaN is false.
16