const mquery = window.matchMedia( "(max-width: 768px)" );

if (mquery.matches) {
// window width is upto 768px
} else {
// window width is more than 768px
}