The screen may be on desktop with a small resolution or a mobile with a wide resolution, as so, combining two answers found here in this question
const isMobile = window.matchMedia("only screen and (max-width: 760px)");
if (/Mobi|Tablet|iPad|iPhone/i.test(navigator.userAgent) || isMobile.matches) {
console.log('is_mobile')
}