A blog focused on programming, debugging, and refactoring real-world code

// Dev notes

function deploySafely()

if (isFriday()) {

console.warn(“Do not touch production.”);

return;

}

deploy();

}

Dev notes

Code is like a joke. If you have to explain it, it’s bad.


Practical code

Quick coding tips

Boost Scroll Performance with passive: true

Make scroll or touch listeners more performant – tell the browser you won’t call preventDefault()

window.addEventListener(
  'scroll',
  onScroll,
  { passive: true }
);

Destructure and Keep the Rest

You can combine destructuring and rest syntax to extract what you need and keep the rest.

const { id, ...info } = { id: 1, name: "Alice", role: "Admin" };
console.log(info);      // { name: "Alice", role: "Admin" }

Run an Event Listener Just Once

You can make an event listener run only once – it removes itself automatically after the first trigger.

button.addEventListener(
  'click',
  handler,
  { once: true }
);

Blog

Latest posts

Category

JavaScript

Category

Front-end Developer Tools

Category

Linux

Category

CSS