JavaScript Reflection with toString

Reflection is an important tool in programming; it lets us examine a language’s structure. Can we reflect in JavaScript? Sort of. Some functions can be reflected with toString(): > const one = () => 1 undefined > one.toString() '() => 1' Very cool! But native functions only return this: > Math.max.toString() 'function max() { [native code] }' You must read the ECMA Script specification to know what the function is required to do. The actual implementation is written in the JavaScript engine, likely in another language like C++, which is why Node can’t show it via toString().

July 10, 2026 · 1 min · Jake Worth

Focus a JS Test

A vital testing skill is focusing a test. When iterating on a failing test, we want that test under microscope. The way I do this in JavaScript is .only: import {describe, expect, test} from 'vitest'; import {sum} from './sum.js'; test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); }); describe.only('adding fours', () => { test('adds 4 + 4 to equal 8', () => { expect(sum(4, 4)).toBe(8); }); }); ...

July 10, 2026 · 1 min · Jake Worth

JSDoc Deprecations in TypeScript

JSDoc has a @deprecated tag that you can use in TypeScript, too. Here’s an example. ...

July 10, 2026 · 1 min · Jake Worth

NPM List Packages

When upgrading a dependency for a security issue, we might upgrade and move on: npm install <dependency>@<version> But wait! Was every <dependency> version upgraded, or just the version in package.json? Check with: npm list // or npm ls ...

July 7, 2026 · 1 min · Jake Worth

Node REPL, No Preview

After version v12.17.0, Node’s REPL provides a useful preview effect. In this example, 2 is shown in gray before I hit enter. > 1 + 1 2 But what if I don’t want that? Here’s a file called repl that disables it as an option: #!/usr/bin/env node const repl = require('node:repl'); repl.start({preview: false}); Then: $ ./repl > 1 + 1 No preview. Docs

June 2, 2026 · 1 min · Jake Worth

NVM Install and Use Latest LTS

With my Node versions managed via NVM, I want to be on the latest LTS. You can ensure that happens with these commands: $ nvm install --lts $ nvm alias default lts/* default -> node (-> v24.16.0) ...

May 29, 2026 · 1 min · Jake Worth

JavaScript Wraparound Index

What I call “wraparound” are repeatable indices on an array. The common use case is a carousel. Here’s how it’s done: const items = ["first", "middle", "last"]; const i = 0; // Our iterable index // "Next" -> const nextIndex = (i + 1) % items.length; // <- "Previous" const prevIndex = (i - 1 + items.length) % items.length;

May 7, 2026 · 1 min · Jake Worth

JavaScript String Concatenation

Here’s a periodic reminder that JavaScript supports string concatenation with a plus sign: > 'foo' + 'bar' 'foobar' ...

May 6, 2026 · 1 min · Jake Worth

JavaScript Spread a String Into An Array

Need an array of letters? Here’s a trick: > const alpha = [...'abcdefghijklmnopqrstuvwxyz'] ...

May 5, 2026 · 1 min · Jake Worth

JavaScript Array Join Comma Default Separator

When you join an array in JavaScript, the default separator is a comma: node> ['j', 'a', 'k', 'e'].join() 'j,a,k,e' ...

May 5, 2026 · 1 min · Jake Worth