How to actually learn to code
Ideas on building habits, getting unstuck, and turning practice into real skill. Written by the people building Devpuff, for the people using it.
Browse every post
Newest first. Filter by category, or search for whatever you're stuck on.
Objects are not valid as a React child: what to render
Objects are not valid as a React child, and React tells you which one by listing its keys. In React 19 the promise version throws a different error.
Read morenpm install errors: read the code, not the stack
Every npm ERR code names one cause. ERESOLVE, E404, EJSONPARSE and the rest, with what each one means, measured against real installs.
Read moreContext windows, tokens and temperature, explained
The LLM context window, tokens and temperature decide what an AI assistant can see and how it answers. Knowing them explains most odd behaviour.
Read moreUnexpected token in JavaScript: the two different errors
Unexpected token is two different errors. One is a typo in your file, the other means you got HTML where you expected JSON.
Read moreHow to convert a string to a number in JavaScript
Converting a string to a number in JavaScript: an empty string is 0 with Number and NaN with parseInt. What four methods do to awkward input.
Read moreSort an array of objects by any property in JavaScript
To sort an array of objects in JavaScript, sort() changes the original in place. The default order is alphabetical even on numbers, so 100 beats 9.
Read moreHow to sleep or wait in JavaScript
JavaScript has no sleep function. The three-line version everyone writes does not block the page, and a busy-wait loop does.
Read moresetTimeout and setInterval explained
setTimeout in JavaScript is a minimum, not a promise. Twenty ticks of a 50ms interval took 1,213ms instead of 1,000, and the drift never comes back.
Read moreRounding in JavaScript: floor, ceil, round and toFixed
Rounding in JavaScript: (1.005).toFixed(2) returns 1.00, because 1.005 is really 1.0049999999999998934. Here is what to use instead.
Read moreRemove duplicates from an array in JavaScript
To remove duplicates from an array in JavaScript, a Set does it in one line and 31 times faster than the filter version. Neither works on objects.
Read moreHow to generate a random number in a range in JavaScript
To get a random number in JavaScript, the Math.round version of the formula gives 1 and 6 half the odds of the rest. Measured over 600,000 rolls.
Read more.gitignore: what to ignore and why it stops working
A .gitignore rule has no effect on a file git already tracks. That one rule explains almost every case where ignoring appears broken.
Read moreHow to undo git add before committing
To undo a git add, git restore --staged unstages the file and keeps your edits. In a repo with no commits yet it fails, and git reset works.
Read moregit stash: park changes without committing
Stash puts your uncommitted work aside and gives you a clean tree. It leaves untracked files behind unless you ask for them.
Read moreHow to squash commits with interactive rebase
Squashing collapses several commits into one. It rewrites them, so every hash changes and pushed history is off limits.
Read moregit reset vs revert vs checkout: undo without fear
Git reset vs revert: reset moves the branch and can destroy work, revert adds a commit and destroys nothing. Each measured on the same repository.
Read moreHow to rename a Git branch, locally and remotely
To rename a git branch locally is one command. The upstream still points at the old remote branch afterwards, which is the step everyone misses.
Read moregit pull vs fetch: the difference, shown
Git pull vs fetch: fetch updates origin/main and leaves your files alone, pull does that and then merges. Here are the refs before and after.
Read moreDetached HEAD in Git: what it means and how to escape
A git detached HEAD means you are on a commit, not a branch. Commits made here are unreachable the moment you leave, and the reflog gets them back.
Read moreDelete a Git branch, locally and remotely
To delete a git branch you need two commands, because local and remote are separate. And everyone else keeps a dead copy until they prune.
Read morez-index not working? It is the parent, not the number
A child with z-index 9999 loses to a sibling with z-index 1 when the parent has opacity. Same markup without it, and 9999 wins.
Read moreCSS variables in practice: scope, fallbacks and theming
Custom properties inherit and cascade, which is what separates them from Sass variables. An invalid value falls back further than you expect.
Read moreCSS units: px, rem, em, vh and when to use each
CSS units compared: nested em compounds to 67.5px where rem stays at 24px. That difference is the whole reason to prefer one over the other.
Read moreCSS transitions: smooth state changes in four properties
Transitioning height to auto does not animate. Measured against an identical box going to a pixel value, one moved and one jumped.
Read moreTruncate text with an ellipsis in CSS, one line or many
Truncating with text-overflow ellipsis in CSS needs three properties, not one. Drop white-space nowrap and text wraps instead of truncating.
Read moref-strings in Python: formatting, specs, and the = trick
An f prefix lets you put expressions straight into a string. The format specs and the debugging form are what make them worth learning properly.
Read moreRecursion explained, with the call stack printed out
Recursion is a function calling itself until a base case stops it. Here is what the call stack does, and the exact depth where JavaScript gives up.
Read moreReact hooks explained, the complete map
React ships around seventeen hooks and you need five. Here is what each one is for, the two rules that break everything, and how to pick the right one.
Read moreHow to actually learn from AI-generated code
You can learn from AI generated code or just ship it. Here is what the research found, and a protocol that keeps the speed without losing the skill.
Read moreHTML forms, the complete beginner guide
HTML forms: a working one is nine lines. Here is that form, what the browser validates for free, and what decides whether a field reaches your server.
Read moreuseEffect explained, dependencies, cleanup, infinite loops
useEffect runs code after render. What the dependency array controls, why cleanup exists, and the four bugs that bite everyone in the same order.
Read moreHow to remove an element from an array in JavaScript
To remove an element from an array in JavaScript, filter() keeps the original and splice() removes in place. Plus the traps that corrupt your data.
Read more
git cherry-pick: move one commit anywhere
Cherry-pick copies a commit onto your current branch. It creates a new commit with a new hash, so the original stays where it was.
Read more
Flexbox vs Grid: how to choose in ten seconds
Flexbox vs grid: flex sizes items to their content, grid sizes the tracks. Measured, that gave 32px and 229px against three equal 193px columns.
Read more
CORS error: what the browser is actually blocking
A CORS error is the browser refusing a response the server already returned with a 200. Here is that proved with two real origins, and the fixes.
Read more
fatal: not a git repository, and how to get out of it
fatal: not a git repository means git found no .git folder here or in any parent. Four causes, and the popular fix that quietly makes things worse.
Read more
How to merge two arrays in JavaScript
To merge arrays in JavaScript, spread and concat both work. push(...arr) throws a RangeError at 200,000 items, which is why the choice matters.
Read more
How to loop through an object in JavaScript
To loop through an object in JavaScript, for...in walks inherited properties too. And integer-like keys come out first, whatever order you wrote.
Read more
"x is not a function" in JavaScript: causes and fixes
The value in front of the parentheses is not callable. Six causes, including the missing semicolon that turns an array into a function call.
Read more
Shallow vs deep copy in JavaScript: how to clone properly
To copy an object in JavaScript, spread copies the top level only, so nested objects stay shared. Here is what each method keeps and destroys.
Read more
JavaScript closures explained with 3 examples
JavaScript closures let a function remember variables around it after the function that made them finished. Three real uses and the classic loop bug.
Read more
How to check if an object is empty in JavaScript
To check if an object is empty in JavaScript, Object.keys(obj).length === 0 is the answer. The JSON.stringify version reports a Date as empty.
Read more
How to capitalize the first letter of a string in JavaScript
To capitalize the first letter in JavaScript the one-liner works until that character is an emoji, whose length is 2 so slice(1) cuts it in half.
Read more
Async await in JavaScript, explained with measured timings
async and await let you write asynchronous code that reads top to bottom. Here is how they work, and the habit that made a real script 4.7 times slower.
Read more
How to check if an array contains a value in JavaScript
To check if a JavaScript array contains a value, includes() finds NaN where indexOf() cannot. On 100,000 items a Set measured 1,245 times faster.
Read more
Indentation Error in Python: the three messages, decoded
Python has three indentation messages and a fourth error that is not an IndentationError at all. Each one points at a different mistake.
Read more
Python for loops: the complete beginner guide
A Python for loop walks a sequence directly, not a counter. Here is every form, including the else clause and the mutation trap.
Read more
append vs extend in Python: the list-growing mixup
Python append vs extend: append adds one item, extend adds each item from an iterable. Extending with a string splits it into characters.
Read more
CSS specificity: why your style is not applying
Specificity is three numbers compared left to right, not one score. Here are the contests that decide it, measured in a browser.
Read more
Pseudo-classes vs pseudo-elements: :hover and ::before
CSS pseudo-classes select an element in a state. Pseudo-elements create something never in your HTML, and on an image they silently do nothing.
Read more
CSS position: static, relative, absolute, fixed, sticky
CSS position has five values, and absolute is the one that catches everyone. Here is what each does to the box and the layout around it, measured.
Read more
position: sticky is not working? Four measured reasons
CSS position sticky needs a threshold and a parent that does not scroll. Here are five identical elements, one that sticks and four that do not.
Read more
CSS overflow: visible, hidden, scroll, auto and clip
Setting overflow-x to scroll silently changes overflow-y to auto. Scrollbars also take 15px out of your content box.
Read more
The CSS display property: block, inline, flex, grid, none
An inline element with width 300px and height 300px measured 36 by 17. Display decides whether your sizes are obeyed at all.
Read more
The CSS box model: what the numbers actually do
A box set to 200px wide can render at 250px. Here is the box model measured in a real browser, and why the computed width will not tell you.
Read more
Beyond console.log: the console methods worth knowing
console.log answers what is this value. Seven other methods answer how many times, how long, who called it, and which of these rows is wrong.
Read more
How to use ChatGPT to learn coding, not to avoid it
Using ChatGPT to learn coding works or wastes your time depending on how you prompt. Here is the test that tells you which one you are doing.
Read more
Cannot read properties of undefined: find the real cause
Cannot read properties of undefined names the property you asked for, not the value that is missing. Here is how to find the real one, measured in Node.
Read more
AI hallucinations in code, and how to catch them
An AI hallucination in code is rarely gibberish. It is a package name that sounds real, and every plausible-but-wrong one tested was already on npm.
Read more
Will AI replace programmers? An honest answer
Will AI replace programmers? No. The same agency projects developers up 15 percent and computer programmers down 6 percent over one decade.
Read more
Git merge vs rebase, with the real graphs side by side
Git merge vs rebase: merge preserves history and adds a commit, rebase rewrites it and adds none. Here is one branch integrated both ways.
Read more
Frontend vs backend, which should you learn first?
Frontend vs backend: learn frontend first. Here is the reasoning, what each side does all day, and the questions that flip the answer.
Read more
CSS flexbox, a guide built on measured layouts
Flexbox is two properties and one axis rule. Here is that model, measured in a real browser, plus the two traps that make flex items misbehave.
Read more
Chrome DevTools for beginners, the 20% you use daily
Chrome DevTools has about twenty panels and you need four. Here is what each answers, the shortcuts worth learning, and debugging without console.log.
Read more
Vibe coding, what it is and exactly where it breaks
Vibe coding means describing what you want and shipping what the AI writes without reading it. It works for four things and fails badly at five others.
Read more
SQL joins explained, which rows survive and why
SQL joins compared: INNER, LEFT, RIGHT, FULL and CROSS on the same two tables, with the real result rows. Plus why the Venn diagram misleads.
Read more
Python for loop with index, enumerate() explained
For a Python for loop with the index, use enumerate(). The syntax, the start argument, and why range(len()) breaks on half of what you loop over.
Read more
How do websites work? Follow one click end to end
How do websites work? Type a URL, press enter, and here is every step in order, from name lookup to the pixels on your screen.
Read more
How to center a div in CSS, every method that works
How to center a div: flexbox does it in two lines. Here is that method, the five others worth knowing, and the two reasons centering silently fails.
Read more
How to undo your last Git commit, every scenario
To undo your last git commit, reset --soft HEAD~1 keeps the work. Here is the version for every situation, including commits already pushed.
Read more
Big O notation explained with everyday examples
Big O notation describes how work grows as your data grows. Count operations instead of timing them and it becomes numbers you can check yourself.
Read moreReading about code is fun. Writing it is better.
Put an idea into practice right now. Write real code in your first free lesson.