Introduction
- codr • Learn JS by solving free coding puzzles. See this 5 minute video by Basarat Ali for a tour. 🧑🎓
- Execute Program • Gary Bernhardt’s interactive programming courses 🧑🎓
- The Birth & Death of JavaScript • Gary Bernhardt 📺
- JavaScript Data Structures: Getting Started • Academind 📺
- JavaScript on Exercism • Get fluent in JavaScript by solving 141 exercises • Exercism 👩🎓
General
- Just JavaScript • Fantastic, beginner-friendly deep dive that aims to correct mistakes in your mental model of how JS works • Dan Abramov & Maggie Appleton 📖
- JavaScript Cheatsheet • Wilfred Inni 📕
Variables
- The “const” Deception •
const
prevents reassignment, not mutation • Josh W. Comeau 📖
Functions
function
keyword vs variable assignment:- one reason defining functions using the function keyword (instead of with variable assignment) can sometimes be preferable: the former are hoisted to the top of the file automatically so you can define them below the code that calls them if you want to
- Sometimes I want to put helpers further down the file (like footnotes) so the main export can sit loud and proud at the top of a file
- Can define anywhere in file, since hoisted (not necessarily above the line that uses it)
- All optional aesthetics, though
Arrays
- Sorting:
- 2 Ways to Sort an Array of Objects by Property Value • Sling Academy
- Sorting on a custom order • Stack Overflow 🧑💻
- Reduce: 10 Different Examples • How to use
Array.reduce()
to process arrays in various ways • Leigh Halliday 📺 - Can you solve this tricky JavaScript Array problem? • Wes Bos 📺
- JavaScript is getting array grouping methods • How to use
Object.groupBy
andMap.groupBy
to group an array of object’s by one of its object properties without needingArray.reduce
• Phil Nash 📖
Filtering an array with an async callback
- Basically, you can’t do it directly because an async function returns a promise, which is always truthy
- Several workarounds
- Simplest is to map, then filter
- JavaScript Array filter with async/await • Stack Overflow 👨💻
- How to use async functions with Array.filter in Javascript • Tamás Sallai 📖
Loop n times
Array.from(Array(10).keys()).forEach(() => {
createBookNode(createNode, { ...dummyBookNode, id: shortid.generate() })
createAlbumNode(createNode, { ...dummyAlbumNode, id: shortid.generate() })
createPodcastNode(createNode, { ...dummyPodcastNode, id: shortid.generate() })
})
or
Array.from({ length: 21 }, (_, i) => i * 0.05);
Generating an array of values that follow a pattern
- e.g.
Array.from({ length: 21 }, (_, i) => i * 0.05)
generates an array of numbers from 0 to 1 in increments of 0.05 - Array.from() • MDN 📚
- generate an array of numbers • Stack Overflow 👨💻
Arrays & Objects
- JS Destructuring in 100 Seconds • How to destructure JavaScript arrays and objects • Fireship 📺
Objects
- Deep Cloning Objects in JavaScript, the Modern Way • It’s been a long time coming, but we finally now have the built-in
structuredClone
function to make deep cloning objects in JavaScript a breeze
Referencing an object’s own properties
Simple way:
const obj = {
a: value => value || obj.b,
b: ‘something’
}
obj.a(true) // true
obj.a(false) // ‘something’
JS has late binding, so obj doesn’t need to be initialized before it is referenced. Be very careful with the way you leverage the power of lexical scoping of mutable references. In this case you are ok because of the use of const, but scary things can happen if you use let or something similar.
More involved way, but safer if not using const:
const createObj = () => {
const b = ‘something’
return {
a: value => value || b,
b: b
}
}
const obj = createObj()
obj.a(true) // true
obj.a(false) // ‘something’
An inlined anonymous function is safer since it limits the number of locations that can mutate the obj reference.
Links:
- Object referencing its own property on initialization • Stack Overflow 👨💻
Maps
- JavaScript Maps are super underrated • Quick video showing how to use
Map.groupBy
to group one array of objects under another • Wes Bos 📺
Promises
- JS Fundamentals: Promise.all / Promise.any • 9 minute video by Leigh Halliday about how
Promise.all()
andPromise.any()
can help when multiple promises are pending at the same time • Leigh Halliday 📺 - JavaScript Promise: .all() vs .allSettled() and .race() vs .any() - DEV Community
- JavaScript waitFor Polling • As more of the JavaScript developers write becomes asynchronous, it’s only natural to need to wait for conditions to be met…
Limiting a number between a minimum and maximum value
- How can I use JavaScript to limit a number between a min/max value? • Stack Overflow 👨💻
- Did this to limit the size of some text (min 3px, max 20px)
- Also,
lodash/clamp
JSDoc
- Use JSDoc: Index • Official documentation for JSDoc 3
Debugging
- Chrome Dev Tools:
- Debugger:
- Debugging JavaScript - Chrome DevTools 101 • Google Chrome Developers demonstrates how to use the Chrome Dev Tools debugger to step through code and inspect variables 📺
- Use XHR/fetch Breakpoints! • David Walsh explains how to use XHR/fetch breakpoints to debug AJAX requests in the Chrome Dev Tools debugger 📖
- Working with the Debugger • Harry Cresswell 📖
- Debugging Node.js, The Right Way • Builder.io 📖
- Performance tab:
- Use the Performance tab to record a page load and see what’s taking the most time:
- Sort by “Self Time” to see which functions are taking the most time to run
- “How to find your slowest lines of code using Chrome’s Performance tab”
- Sort by “Network” to see which resources are taking the most time to load (true?)
- Sort by “Self Time” to see which functions are taking the most time to run
- Use the Performance tab to record a page load and see what’s taking the most time:
- Debugger:
- Safari Dev Tools:
- Debugger:
- Debugging iOS Safari JS issues on a mac • Wes Bos demonstrates how to use the macOS Safari Dev Tools to debug an issue happening in iOS Safari 📺
- Debugger:
console.log
:- Make the most of your console.log() • Builder.io 📖
Bun
- Bun is disrupting JavaScript land • Fireship 📺
maybeString ?? ''
vs String(maybeString)
vs maybeString.toString()
String(maybeString)
— was my default, and works great for converting numbers and booleans to their string versions; but has the problem of turning null and undefined into the literal strings “null” and “undefined”. that’s never what i wantmaybeString ?? ''
— generally what I want for a string | null/undefined case; if null/undefined, give me an empty string so I’m still passing the expected type (a string)maybeString.toString()
- if you want to convert numbers, booleans, etc to strings, but throw an error on null/undefined instead of allowing a backup value (like an empty string)
Concurrency & Parallelism
- PROOF JavaScript is a Multi-Threaded language • Intro to Node Worker Threads and browser Web Workers • Beyond Fireship 📺
Inbox
- https://gomakethings.com/simpler-boolean-returns-in-functions-with-javascript/
- https://kilianvalkhof.com/2023/javascript/a-small-javascript-pattern-i-enjoy-using/
- ✍️ What is a Factory Function?
- Lean Web Club • Learn a simpler way to build for the web with HTML, CSS, and vanilla JS. Get instant access to a growing collection of tutorials, projects, structured learning paths, and a supportive developer community.
- Why I’ve stopped exporting defaults from my JavaScript modules - Human Who Codes • After years of fighting with default exports, I’ve changed my ways.
- “Tip: The Intl.RelativeTimeFormat API gives us localized formatting of relative times (e.g. “yesterday”, “3 seconds ago”, “in 2 weeks”)… • Addi Osmani 💬
- Intl.RelativeTimeFormat • The Intl.RelativeTimeFormat object is a constructor for objects that enable language-sensitive relative time formatting (e.g., “3 hours ago”) • V8 JavaScript Engine
- String replacement in console.log • StackOverflow 💬
- How can I turn my JavaScript code into a bookmarklet? - Stack Overflow - wrap in
javascript:(function() { ... })()
- javascript - How to convert a bookmarklet into a Greasemonkey userscript? - Stack Overflow - convert a bookmarklet to js by copying it, running it through
decodeURI()
, and removing the leadingjavascript:
- Bun — A fast all-in-one JavaScript runtime
- Fast, disk space efficient package manager | pnpm
- Pesky little scripts | Redowan’s Reflections • start all script and alias names with a comma to get tab completion that separates your commands from system commands
- javascript: weird dependency-related errors only one team member is experiencing: check what version of node is active in their terminal; if wrong version, switch versions, recreate node_modules and try again; if that was the fix, recommend automatically switching node versions in directories containing an
.nvmrc
- components: UI Composition | Kyle Shevlin • How to composing compound components (e.g.
Card
,Card.Wrap
,Card.Section
,Carr.Divider
) can help prevent overloading a component with too much conditional rendering and styling logic • Kyle Shevlin 📖 - htmx
-
htmx - high power tools for html • htmx gives you access to AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext
-
htmx in 100 seconds • Fireship 📺
-
The Simplest Tech Stack • HTMX + Go • Awesome Code 📺
-
Is The HTMX Hype Legit? • Awesome Code 📺
-
FULL Introduction To HTMX Using Golang • Two-hour Frontend Masters lecture • The Primeagen 📺
-
- signals:
- Why Signals Are Better Than React Hooks • Web Dev Simplified 📺
- Objects: check out new methods like groupBy
- Arrays: check out new methods like toSorted
- VanJS - A 1.0kB No-JSX Framework Based on Vanilla JavaScript 🛠️
- Array.prototype.toSorted() - JavaScript | MDN - use
Array.toSorted
instead ofArray.sort
to return a new, sorted copy instead of mutating the original array - MDN