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. ...
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. ...
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.
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.
Today, after waiting for an album review to load, I built something small: my own take on the Pitchfork aggregate review loading experience. ...
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. ...
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! ...
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
Astro’s default port is 4321. Like Vite, this project is trying to convey its (rocket-launch) branding, even in this small detail. ...
Node Timeout timers have a private boolean attribute called _destroyed. It tells you if the function has been cleared: timer._destroyed; ...
Today I used JavaScript to mass-unsubscribe from a website’s email notifications. Here’s the code, followed by what I did and why. document .querySelectorAll('[role="switch"]') .forEach((element) => element.click()); ...