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
fill() reuses one object 🧩 const rows = Array(2).fill([]); rows[0].push("x"); // rows is [["x"], ["x"]] fill() puts the SAME reference in every slot. For separate arrays use Array.from({ length: 2 }, () => []).
2
slice() can cut an emoji in half ✂ const s = "hi👋"; s.slice(0, 3); // "hi\ud83d" (broken) [...s].slice(0, 3).join(""); // "hi👋" Indexes count UTF-16 units, and 👋 takes two. Spread into characters first when you trim text for a preview.
8
Number(null) is 0, Number(undefined) is NaN 🧮 Number(null) // 0 Number(undefined) // NaN Number("") // 0 Number(" 12 ") // 12 null becomes 0, undefined has no number, and an empty or blank string also becomes 0.
11
with() returns a copy with one item replaced 🔁 const arr = [1, 2, 3]; const next = arr.with(1, 9); // next: [1, 9, 3] // arr: [1, 2, 3] (unchanged) Like toSorted(), it doesn't mutate. arr[1] = 9 changes the original; with() gives a new array.
8
padStart() pads to a length 🔢 "7".padStart(3, "0"); // "007" "abc".padStart(2, "0"); // "abc" String(5).padEnd(3, "-"); // "5--" The first argument is the target length, not how many to add. Longer strings are left untouched. Handy for zero-padded times and ids.
17
toSorted() sorts a copy 🗂️ const nums = [3, 1, 2]; const sorted = nums.toSorted(); sorted; // [1, 2, 3] nums; // [3, 1, 2] Unlike sort(), which reorders the original array in place, toSorted() returns a new sorted array. Same for toReversed().
16
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.
18
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.
16
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.
17
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.
12
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
41
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.
16
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.
15
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.
15
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
34
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.
23
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.
18
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.
21
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
24
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.
29