How to include a JavaScript file in another JavaScript file

JavaScript has no #include. It has modules, and in the browser it has script order — and the second one is where most of the errors come from.

How to make Git forget a file that is already tracked

You committed something you should not have — a .env, a build directory — then added it to .gitignore and it kept showing up. That is not a broken ignore rule. .gitignore is not consulted for files git already tracks.

How to remove a specific item from an array in JavaScript

There are two answers, and which one you want depends on a question nobody asks out loud: do you want a new array, or do you want this array changed?

How to remove untracked files from a Git working tree

git clean removes files git is not tracking. It is the right tool, and it is also one of the two or three git commands that can genuinely lose work, so it is worth being deliberate about.

How to rename a Git branch

Renaming a local branch is one command. Renaming one that is already on a remote is three, and the one people leave out is the one that keeps the branch pointing at the right place afterwards.

How to round to at most 2 decimal places in JavaScript

The two answers everyone gives are +x.toFixed(2) and Math.round(x * 100) / 100. They are usually presented as the same thing. Over 100,000 values they differ on 3,435 of them.

How to sleep in JavaScript

JavaScript has no blocking sleep, and that is deliberate: one thread runs your code and the timers and the clicks, so a thread that sleeps stops all three.

How to undo git add before committing

You staged something you did not mean to. Taking it back out of the index is one command — but there is a very similar command one word away that throws the change itself away, so it is worth knowing which is which.

How to undo the most recent commits in Git

Git is a distributed version control system. Undoing the last commit is something everyone needs in their first week, and the command you want depends on whether you also want to keep the changes — and on whether the commit has already been pushed.

How to validate an email address in JavaScript

Everyone wants the regex. The interesting result is what happens when you run the popular one next to the browser’s own check on the same inputs: they disagree on five out of ten.