Comma Operator Return in JavaScript

I love learning something new that’s core to the JavaScript language syntax! A code exercise I completed today did just that. Via this comma, items is returned. const removeItemAtBottom = (items) => (items.shift(), items); const cards = [1, 2, 3, 4, 5]; removeItemAtBottom(cards); // [ 2, 3, 4, 5 ] This helps us around the fact that shift() returns the removed item, 1, rather than the list of items that we modified. It works outside a function as well: ...

October 1, 2026 · 1 min · Jake Worth

Writing Math.max in JavaScript

For a recent talk I examined some JavaScript implementations in Node, and ended up reading the source code for Math.max, which does this: Math.max(100, 1); // 100 Here’s the code: extern macro Float64Max(float64, float64): float64; transitioning javascript builtin MathMax( js-implicit context: NativeContext)(...arguments): Number { let result: float64 = MINUS_V8_INFINITY; const argCount = arguments.length; for (let i: intptr = 0; i < argCount; i++) { const doubleValue = TruncateTaggedToFloat64(arguments[i]); result = Float64Max(result, doubleValue); } return Convert<Number>(result); } To better understand this function, I decided to write my own implementation in JavaScript: ...

September 27, 2026 · 1 min · Jake Worth

JavaScripting on main()

I had ChatGPT write a JavaScript for me, and was surprised to see this arrangement: function main() { // Do work... } try { main(); } catch (error) { console.error(error); process.exitCode = 1; } I would not have written this file this way; instead, I’d have put a try/catch in the file directly and probably forgotten the exit code. This lets my script return nonzero on any error and be chained with other scripts. And it encapsulates the work in main(), a C-like flourish I admire.

September 23, 2026 · 1 min · Jake Worth

toString can be set in JavaScript

A while ago, I wrote that you can use .toString() to reflect about user-defined functions in the JavaScript runtime. There’s a catch— this value can be set, making it not a reliable way to reflect the function. ...

September 9, 2026 · 1 min · Jake Worth

Read Node's Process Versions

Node has a key process.versions that can tell us a lot about itself. Here’s one its many keys, telling me the V8 version of my Node with the -p / --print flag: node --print process.versions.v8 14.6.202.34-node.28 See node --print process for more.

September 9, 2026 · 1 min · Jake Worth

JavaScript Reflection Preserves Comments

In JavaScript reflection with .toString(), comments are preserved. const hello = () => { // returns "Hello" return 'Hello'; }; hello.toString(); // '() => {\r // returns "Hello"\r return "Hello";\r}' Note the comment in the returned string.

September 9, 2026 · 1 min · Jake Worth

Building a Pitchfork-Style Loading Skeleton

Today, after waiting for an album review to load, I built something small: my own take on the Pitchfork aggregate review loading experience. ...

September 2, 2026 · 3 min · Jake Worth

Link to Local Package With npm link

When developing a local Node module, we might want to point another project’s package.json at the local module. Here’s how you do that. ...

September 2, 2026 · 1 min · Jake Worth

Don't Use npm init on an Existing Project

npm init is a nice tool for initializing a package.json. Today I learned that you should not use it on an existing JavaScript project! ...

August 25, 2026 · 1 min · Jake Worth

Enumerate on promise resolved

For the golfers out there, we can combine these two lines into one: const items = await getCollection(); return items.sort(); This doesn’t work because sort() is being called on the promise returned by getCollection(): return await getCollection().sort(); // `sort()` runs on the Promise Instead, wrap the await expression in parentheses so sort() is called on the resolved value: return (await getCollection()).sort(); // `sort()` runs on the resolved array Promise documentation - MDN

July 24, 2026 · 1 min · Jake Worth