How can I use `javascript` to detect mobile browsers reliably?

With about five years in front-end-heavy projects, I’ve learned that sometimes, it’s not about the device — it’s about the actual environment. You might want to know: is the screen small? Does it support coarse touch (like fingers)?

function isMobileDevice() {
  return window.matchMedia("(pointer: coarse)").matches && window.innerWidth <= 768;
}

console.log(isMobileDevice()); // true or false

:brain: When this helped me: I was working on a game where the experience had to adjust based on input style, not device brand. This javascript detect mobile approach let me tailor the UI based on the real conditions: small screens, touch interfaces — not just labels like “iPhone” or “Android.”