const mq = window.matchMedia( "(min-width: 500px)" ); if (mq.matches) { // window width is at least 500px } else { // window width is less than 500px }