Member-only story
Featured
30 JavaScript One-Liners That’ll Make You Feel Like a Senior Dev
You can build a full app and still feel like there’s always one more thing to learn. But sometimes, it’s the tiny snippets — those one-liners that do in one line what you used to do in fifteen — that make you feel like a real developer.
Over the years, I’ve collected small JavaScript tricks that made me faster, clearer, and a bit prouder of my code. Here are 30 of my favorite one-liners that can save your day — and your sanity — when you least expect it.
1. Get a Cookie Value
const cookie = name => `; ${document.cookie}`.split(`; ${name}=`).pop().split(';').shift();Why it matters: Sometimes you just need to quickly check a cookie value for debugging — like when login sessions misbehave.
Note: You can’t access HttpOnly cookies (for security reasons), and domain/path restrictions still apply.
2. Convert RGB to Hex
const rgbToHex = (r, g, b) => "#" + ((1<<24)+(r<<16)+(g<<8)+b).toString(16).slice(1);Use case: Designers love RGB, CSS loves hex. This line helps both get along.
Always validate numbers between 0–255 — or you’ll end up with weird colors (been there).

